A Baltimore police officer charged in the death of Freddie Gray asked an appeals court Thursday to block a ruling that would force him to testify against a colleague, arguing that it's a violation of his Fifth Amendment rights against self-incrimination.

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 Gary Proctor filed court papers asking the Maryland Court of Special Appeals in Annapolis to block that ruling so that Porter 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.

Proctor argued in the filing that prosecutors won't be able to discern what they heard in Porter's first trial, when he was a defendant, and what they hear when he testifies as a witness.

"The bell cannot be unrung," he wrote.

Although Porter's witness testimony can't be used against him at trial, Proctor writes, immunity doesn't protect him from a perjury charge if his statements contain inconsistencies. What's more, he argued, prosecutors during Porter's trial told jurors that his statements were lies. Prosecutors could make the same argument even if Porter's witness statements are identical to his previous testimony.

If Porter does not testify, "he will go to jail. If he does, and he reiterates what he repeated before, the state has already called that perjury, for which Porter has been offered no protection. If he deviates in any way from his earlier testimony then it is perjury, for which Porter remains defenseless."

It is unclear whether a hearing on the matter will be held, or if an order will be issued in writing.

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 "material and necessary."

Porter's attorneys had said he would invoke his Fifth Amendment right, but the ruling means he risks being held in contempt if he does so. The ruling is unprecedented in the state 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.