Officer William Porter, right, arrives at Courthouse East with his attorneys Wednesday, Jan. 6, 2016, in Baltimore. Circuit Judge Barry Williams is holding a motions hearing Wednesday ahead of the trial for Caesar Goodson, who drove the police transport van where Freddie Gray was critically injured. Prosecutors want Porter, whose trial ended in a mistrial last month, to testify against Goodson and Sgt. Alicia White. (Jerry Jackson/The Baltimore Sun via AP)
Officer William Porter, right, arrives at Courthouse East with his attorneys Wednesday, Jan. 6, 2016, in Baltimore. Circuit Judge Barry Williams is holding a motions hearing Wednesday ahead of the trial for Caesar Goodson, who drove the police transport van where Freddie Gray was critically injured. Prosecutors want Porter, whose trial ended in a mistrial last month, to testify against Goodson and Sgt. Alicia White. (Jerry Jackson/The Baltimore Sun via AP)

The retrial of a Baltimore police officer charged in the death of Freddie Gray could be compromised by prosecutors’ insistence on using his testimony against a colleague, a judge warned.

Baltimore Circuit Judge Barry Williams ruled in the state’s favor that William Porter, whose trial ended in a mistrial last month, can be compelled to take the stand in the trial of van driver Caesar Goodson or face the possibility of jail time.

Porter’s attorney asked an appeals court on Thursday to block that ruling so that the officer can’t be forced to testify.

Goodson is facing the most serious charge of the six officers charged in the case — second-degree murder — in addition to manslaughter, assault, misconduct in office and reckless endangerment. Porter’s retrial is scheduled for June 13.

Prosecutors plan to offer Porter immunity, meaning they can’t use his own testimony during Goodson’s trial against him later. But Williams warned that keeping Porter’s accounts separate could be difficult.

“I will note if Mr. Porter testifies at a trial that’s not his, once you’ve heard something, how will you put that out of your mind when you cross-examine him?” Williams asked Chief Deputy State’s Attorney Michael Schatzow. “The second he testifies, it might change the game.”

The ruling could have sweeping ramifications. Although its immediate effect on other cases is unclear, the judge warned prosecutors that calling Porter as a witness against Goodson could make it more difficult to put Porter on trial again.

In a September letter to the court, prosecutors indicated they intended to call Porter as a witness against both Goodson and another officer, Sgt. Alicia White, arguing that his testimony is crucial. But Porter’s attorneys had said in court documents he planned to invoke his Fifth Amendment right against self-incrimination if called to the stand. Now, Porter is no longer able to do so; if he does, he can be held in contempt of court and potentially jailed.

No such ruling has ever been made in the state of Maryland and could have tremendous implications for future cases.

“I’m in uncharted territory,” Williams said while issuing the ruling.

Longtime Baltimore defense attorney Warren Brown, who is not involved in the Gray case, said Williams’ decision is extraordinary. The judge is essentially saying there is no difference between a witness and a defendant, so long as immunity is granted, he said. And he said that could make it difficult for people to get a fair trial in future cases involving several defendants.

“This has never happened in the state of Maryland. It’s only in regard to an investigation that a person is given immunity,” Brown said, adding that “it’s almost sacrilegious to make a defendant testify by giving him or her immunity, and that’s why it’s never occurred.”

But Douglas Colbert, a University of Maryland Law professor, said the judge’s decision wasn’t surprising. He said it protects Porter because he’s granted immunity but also protects the prosecution’s case. He also noted the case was highly unusual, given how rare it is to prosecute police officers.

“Otherwise, any time you had co-defendants, they’d all gang up together and say, ‘Everybody keep quiet. Let’s not cooperate.’ And who gets defeated? The public does, because the public doesn’t learn the truth that would allow for some of those people to take responsibility and be found guilty,” he said.