A divided federal appeals court this week struck down a Virginia law for “effectively criminalizing an illness” by targeting homeless alcoholics for buying, consuming or having alcohol.

The narrowly decided case reversed an earlier ruling from a three-judge panel of the same court, provoked lengthy, passionate dissent and indicated deep divisions on a court known for its civility and genteel traditions.

In its 8-7 decision, the U.S. Court of Appeals for the 4th Circuit invalidated the law as “unconstitutionally vague” because it does not provide fair warning to would-be offenders and singles out homeless alcoholics based on their addiction to alcohol.

“Without question, the many homeless citizens of Virginia who struggle with the effects of alcohol on their mental and physical health are entitled to guidance and fair notice under the law. They have not been given such direction,” Judge Diana Motz wrote for the majority.

“While necessary changes in the law may not alter the choices that they make or enhance the quality of their life, at least the government will not be compounding their problems by subjecting them to incarceration based on the arbitrary enforcement of ambiguous laws or, at best, the targeted criminalization of their illnesses.”

At issue is a state law, dating to the 1870s, that allows for the prosecution of people designated in court as “habitual” drunks for consuming or having alcohol. The lawsuit was brought by four men, who according to their lawyers are homeless and struggling with alcoholism. The label meant that the men could be subject to up to a year in jail if caught with alcohol. In the past decade, each man was prosecuted in Virginia at least 11 times.

Virginia is one of only two states, if not the only state, with such a law on the books, according to advocates seeking to get rid of the measure.

“The Constitution cannot allow for the criminalization of illness and homelessness,” Elaine Poon of the Legal Aid Justice Center said in a statement after the ruling. “We look forward to telling our clients about this victory, so that they can pursue their lives without the constant fear of arrest and prosecution.”

The office of Attorney General Mark R. Herring (D), which defended the law before a full complement of 15 judges, is reviewing the decision and declined to comment on next steps.

The ruling on Tuesday highlighted new alliances on the Richmond-based appeals court that includes three new judges appointed by President Trump.

In addition to finding the law “unconstitutionally vague,” the majority said the men had presented a valid claim that the law violates the Eighth Amendment because it punishes people for who they are rather than for their actions.

“What the Eighth Amendment cannot tolerate is the targeted criminalization of otherwise legal behavior that is an involuntary manifestation of an illness,” Motz wrote.

Motz noted that the decision leaves untouched other penalties that apply to the general population such as those for underage drinking and prohibitions against driving while intoxicated.

The dissenting judges warned the court’s ruling would lead to “ruinous consequences,” making it more difficult for law enforcement to protect citizens from alcohol-related violence and putting victims of domestic abuse and sexual assault in harms way.

“This case is an assault upon the constitutional, democratic, and common law foundations of American civil and criminal law, and most importantly, to the judge’s place within it,” wrote Judge J. Harvie Wilkinson III.

Wilkinson said the majority opinion is at odds with past Supreme Court rulings and other appeals court decisions finding that states may criminalize behavior even when an addiction created a strong urge — or compulsion — to engage in the particular act.

The majority, he wrote, ignores the “painful reasons why states regulate alcohol in the first place. Reading the majority’s opinion, one would be forgiven for thinking the majority was discussing soda pop.”

He went on to write, “It is hard to imagine a decision so infused with ruinous consequences or so insensitive to a judge’s inability to rework society from the bench.”

Wilkinson was joined by five others, including two judges nominated by Trump — Judges Julius N. Richardson and A. Marvin Quattlebaum Jr. The president’s third nominee to the court, Allison Jones Rushing, was not on the bench at the time of oral argument.

Judge Albert Diaz wrote a separate dissent.

It was Wilkinson’s dissent that prompted an unusual response from Judge Barbara Milano Keenan. The “attacks” on the majority and “the alarmist tone of the principal dissent warrants separate comment,” she wrote.

The assertions from the dissent, she wrote suggest “malfeasance by judges who disagree.”

“I express hope that we will turn away from the use of inflammatory language, which diminishes the value of our work.”

Wilkinson replied directly, writing separately to say that the purpose of a dissent was to “illuminate difference, not evidence disrespect.” He assured his colleagues that “being wrong, even woefully, wrong is in no way malfeasance,” but said calls for civility should not be used to “drain or dilute dissenting voices.”

“We have in this case a deep and honest difference of opinion,” he wrote, “the importance of which can neither be brushed off nor wished away.”