A judge who said police improperly targeted gay men in sting operations has dismissed charges of lewd conduct and indecent exposure against a man who was arrested in a public bathroom.

Superior Court Judge Halim Dhanidina ruled Friday that Rory Moroney's arrest in 2014 was based on discriminatory enforcement and prosecution, the Long Beach Press-Telegram reported (http://bit.ly/1VZ5GJH ).

If convicted, Moroney would have been required to register as a sex offender for life.

Moroney, 50, was arrested after a detective acting as a vice unit decoy said he exposed himself in a bathroom at Recreation Park in the Los Angeles suburb.

Moroney said the detective, who smiled, nodded and made eye contact in the restroom, appeared to be interested in sex.

During the trial, police indicated that they had arrested about 55 men for lewd conduct in the past two years.

Police said they based lewd-conduct operations on complaints, but the judge said there was little evidence of such complaints at the men's restrooms where most stings took place.

"The presence and tactics of the decoy officers actually caused the crimes to occur," Dhanidina ruled.

"The arbitrary enforcement of the law as seen in this case undermines the credibility of our legal system, eroding public confidence in our ability to achieve just results," the judge said in his closing remarks.

"This judge knows discrimination when he sees it," said Bruce Nickerson, one of Moroney's defense lawyers. "His ruling is powerful because it sends a message far beyond this case. It sends a message to police departments throughout the state who do these decoy operations for lewd-conduct cases."

In 1996, Nickerson won a decision from the California Supreme Court that police in Mountain View discriminated against gay men in lewd conduct arrests.

The Long Beach Police Department said in a statement that it is taking the court ruling seriously "and will evaluate how we respond to these kind of complaints."

Police Chief Robert Luna said the department is "100 percent committed to civil rights and equality for all people, including the LGBTQ community" and has many openly homosexual employees.

City Prosecutor Doug Haubert said his office would review the ruling before commenting.