A federal appeals court ruled in favor of a Virginia man who was ordered as a teen by a lower court to be photographed while masturbating in the presence of armed police officers.

Trey Sims from Manassas, Virginia, was 17 years old when he was accused of sending pictures of his genitals to his then 15-year-old girlfriend in 2014, according to court documents. He was charged with child pornography the same year.

In 2016, Sims filed a federal civil rights suit alleging Detective David E Abbott Jr. forced him to pull down his trousers so the police could take pictures of his penis to compare with the graphic images on his girlfriend's phone.

Abbott obtained a search warrant authorizing photographs of Sims' "naked body, including his erect penis," Fourth Circuit Judge Barbara Keenan wrote in court documents released Tuesday.

Keenan also noted Abbott ordered Sims to “manipulate his penis” to get an erection, while two other uniformed officers were present. When that did not succeed, Claiborne Richardson, the assistant Prince William county commonwealth's attorney, and Abbott obtained a second search warrant and threatened to take Sims to a hospital “to give him an erection-producing injection.” This injection ultimately never took place due to a massive public outcry.

Abbott committed suicide in December 2015 when officers came to arrest him on separate charges relating to pedophilia, ARS Technica reported.

Sims filed a lawsuit against Kenneth Labowitz, the administrator of Abbott's estate, and Richardson who police said instructed Abbott to get the warrant.

A district court determined Labowitz was entitled to qualified immunity and dismissed Sims' complaint, the Daily Mail reported. An appeal was filed by Sims and on Tuesday, the U.S. Court of Appeals announced their decision to reverse the district court's decision.

“Construing the facts in the light most favorable to Sims, a reasonable police officer would have known that attempting to obtain a photograph of a minor child's erect penis, by ordering the child to masturbate in the presence of others, would unlawfully invade the child's right of privacy under the Fourth Amendment,” court documents stated. “We cannot perceive any circumstance that would justify a police search requiring an individual to masturbate in the presence of others.”

In the three-judge panel, Keenan was joined by Judge Albert Diaz, but Judge Robert Bruce King went against the two judges.

“Where a police officer has sought and obtained a search warrant and acted within its scope,” King wrote, “the resulting search is presumptively reasonable…In my view, no reasonable police officer or lawyer would have considered this search warrant, duly issued by the Virginia magistrate, to violate a clearly established constitutional right.”

Sims’ attorney Vic Glasberg said the ruling did not create any new law.

“It is settled law,” Glasberg stated, according to The Washington Post, “that the mere issuance of a warrant by a magistrate — who in Virginia need not even be a lawyer — does not immunize an officer who requests or executes an unreasonable warrant. The issue was: is it unreasonable for police officers to force a minor to take down his pants and manipulate his penis for a photograph. Most people agree it is. This is what the court held, and also that Detective Abbott should have known it.”