Apparently not much has gone right for Amarcion D. Henderson, who was a daily pot smoker by age 14, a felon by his early 20s and then picked up on a gun charge, his attorney told the Supreme Court on Wednesday, before he’d even had time to do anything “seriously wrong” with the weapon.

He was sentenced to a long prison term on the hope that he would receive drug treatment. He didn’t.

And on Wednesday, as Supreme Court justices noted, one after another, that Henderson’s prison sentence was improper, there was hardly a corresponding view that anything should be done about the extra time he served.

“There’s always an injustice when the district court has gotten it wrong,” Justice Antonin Scalia said. “The district court got it wrong, applied the wrong rule. Justice has not been served.”

But at the same time, Scalia continued, “we don’t say, ‘We want to do justice.’ We say, ‘We’re only going to do justice if it was clear’ ” to all at the time that a mistake was being made.

The mistake in Henderson’s case was that the federal statutes on sentencing do not allow a judge to extend someone’s sentence in order to facilitate drug rehab. But that was not settled law when a judge sentenced Henderson to five years in prison, above the federal guidelines of 33 months to 41 months.

By the time the U.S. Court of Appeals for the 5th Circuit considered Henderson’s appeal, it had been settled. A unanimous Supreme Court in 2011 said the federal statute was clear that “a court may not impose or lengthen a prison sentence to enable an offender to complete a treatment program or otherwise promote rehabilitation.”

But the appeals court upheld Henderson’s sentence anyway, because at the time of his guilty plea, it was not “plain error” for the judge to have imposed the sentence he did. And plain error is part of the test that courts must use to decide whether to get involved when a defendant’s lawyer has not objected to a judge’s mistake.

Henderson’s attorney, Patricia A. Gilley, who also was representing him at the Supreme Court, acknowledged under questioning from Justice Ruth Bader Ginsburg that she was not aware of the statute forbidding prison sentences for rehabilitation. Neither she nor the prosecutor told the judge that the sentence might be improper.

Much of the court’s discussion focused on what Justice Anthony M. Kennedy called the “metaphysics” of defining “plain error” and why it is necessary in order for courts to right wrongs.

Assistant Solicitor General Jeffrey B. Wall said that because it was an unsettled question whether judges could lengthen sentences for rehabilitation, Gilley should have objected rather than remain silent at his sentencing.

It is “exactly the kind of debatable, open, unsettled legal question that our adversarial system counts on parties to raise every day,” Wall said.

He received support for the view from Scalia and Justice Samuel A. Alito Jr. They both said the federal rule on “plain error” was meant to enhance the efficiency and finality of the judicial system.

It should not relieve the lawyer of filing proper objections, and then using that to prolong appeals, they offered.

But Justice Stephen G. Breyer said that no lawyer would fail to file objections in hopes that the law might one day turn in favor of his clients and that he could then appeal a decision because of plain error. “The lawyer who thought that is like the unicorn; he doesn’t really exist,” Breyer said.

He added: “Sometimes there is a case where just simple fairness, plus the fact that the law is now plain, means that the appellate court should treat this person the same as a thousand others who now will be treated according to the new law.”

Alito, too, although concerned about what the court’s ruling could mean for the system, wondered about the person at the center of the case.

“What about Mr. Henderson sitting in prison, serving a sentence that we now know was imposed for a reason that is not permitted under federal sentencing law?”Alito asked at one point. “Is there anything that can be done for him?”

It might not matter, in the long run. Gilley said her client is eligible to be released from prison in May.

The case is Henderson v. United States .