The state's highest court is considering a case that could have implications for needle exchange programs across Massachusetts.

Justices for the state's Supreme Judicial Court on Tuesday heard arguments in an almost year and a half long fight between the town of Barnstable and the AIDS Support Group of Cape Cod over the group's needle exchange program in Hyannis.

Barnstable officials issued a cease and desist order against the program back in 2015, saying it was behind the large numbers of discarded needles littered around Hyannis. The group took the town to court, where a lower court judge issued a preliminary injunction against the town's order so the two sides could negotiate.

The town says while it understands clean needle distribution programs, it also has to consider the health of all town residents who may come in contact with carelessly tossed needles. The town also questioned whether the group is operating legally — and that was the crux of their argument before the SJC.

Charles McLaughlin, an attorney for Barnstable, told the court Tuesday that when the state decriminalized the possession of needles in 2006, it limited needle distribution to pharmacies and programs run by the Department of Public Health.

Justice Margot Botsford asked McLaughlin if someone gave someone else a needle, whether the law said they were doing something illegal.

"In express language it doesn't," McLaughlin said.

"So how is he supposed to know he violated anything?" Botsford asked.

"Because the Legislature has expressed itself with specificity that there are two methods of distribution," McLaughlin responded.

But attorneys for the AIDS Support Group of Cape Cod say the 2006 law was designed to lift any prohibition on needle distribution. The group says the current opioid epidemic makes its work even more relevant now.

Ben Klein, who argued for the group, says the law does not stop a private group from handing out clean needles, which he says helps prevent the spread of diseases associated with intravenous drug use, such as hepatitis C and HIV.

"We're facing an opioid epidemic where people are contracting devastating and deadly diseases because they don't have access to clean needles," Klein said. "These are entirely preventable diseases and that's what the Legislature intended to solve."

The AIDS Support Group of Cape Cod has been operating the Hyannis program for two and a half years. Joe Carleo, the group's CEO, says on average they serve about 12 people a day either by providing clean needles or offering the opioid overdose reversal drug Narcan.

"My hope is that the ruling is in our favor and that we continue and that we can help other programs do the same thing," Carleo said.

Carleo says his group has been working with Barnstable officials — meeting with them regularly and doing things such as sweeping around the program building daily and helping to carefully dispose of used needles.

The group says the court's decision in this case will ultimately determine how much access drug users have to clean needles across Massachusetts.