A federal judge in Newark has thrown out a lawsuit against the New York Police Department for spying on New Jersey Muslims, saying if anyone was at fault, it was the Associated Press for telling people about it.

In his ruling Thursday, U.S. District Court Judge William J. Martini simultaneously demonstrated the willingness of the judiciary to give law enforcement alarming latitude in the name of fighting terror, greenlighted the targeting of Muslims based solely on their religious beliefs, and blamed the media for upsetting people by telling them what their government was doing.

The NYPD’s clandestine spying on daily life in Muslim communities in the region — with no probable cause, and nothing to show for it — was exposed in a Pulitzer-Prize winning series of stories by the AP. The stories described infiltration and surveillance of at least 20 mosques, 14 restaurants, 11 retail stores, two grade schools, and two Muslim student associations in New Jersey alone.

In a cursory, 10-page ruling issued before even hearing oral arguments, Martini essentially said that what the targets didn’t know didn’t hurt them:

None of the Plaintiffs’ injuries arose until after the Associated Press released unredacted, confidential NYPD documents and articles expressing its own interpretation of those documents. Nowhere in the Complaint do Plaintiffs allege that they suffered harm prior to the unauthorized release of the documents by the Associated Press. This confirms that Plaintiffs’ alleged injuries flow from the Associated Press’s unauthorized disclosure of the documents. The harms are not “fairly traceable” to any act of surveillance.

The NYPD didn’t publicize the program, the judge wrote. “The Associated Press covertly obtained confidential NYPD documents and published unredacted versions of these documents, as well as articles interpreting the documents.”

The AP declined to comment.

Martini, a one-term Republican congressman from New Jersey, was appointed to the federal bench by George W. Bush in 2002. Previous critiques of his judicial conduct have been unusually blunt and public, including repeated rebukes at the appellate level and the local U.S. attorney’s describing him in court filings as “misguided” and “irrational.”

Nevertheless, Martini is still on the bench (it’s very hard to unseat a federal judge). And his ruling was perhaps the most extreme example yet of what is becoming the nearly standard reaction by the modern American political and law-enforcement elite’s reaction to exposure of secret conduct that merits public scrutiny: trying to shoot the messenger.

“In a suit like this, the complaint is that the government did the surveillance, not that it became public knowledge,” Gregg Leslie, legal defense director for the Reporters Committee for Freedom of the Press, told The Intercept.

“The fact that the surveillance occurred is what causes a constitutional violation, so it’s very disingenuous to say that any harm was done by any reporting on it. The harm was done when they violated the Constitution by spying on them.”

Tom Rosensteil, executive director of the American Press Institute, told The Intercept that there are indeed cases where journalists should not publish everything they know. “These issues are not always so clear cut,” he said.

But the key question, he said, is “Is the publication of the story in the public interest?” Does the benefit outweigh the harm?

“The notion that the press shouldn’t be watching, and shouldn’t be providing some healthy skepticism and check on government overreaching? We want the press to do that. Any inference that we don’t want the press to be writing about these things would be a mistake,” Rosensteil said.

Martini’s ruling was also notable for its embrace of guilt by association:

Plaintiffs must plead sufficient factual matter to show that the City adopted and implemented the surveillance program not for a neutral, investigative reason but for the purpose of discriminating on account of religion. … [T]he Plaintiffs in this case have not alleged facts from which it can be plausibly inferred that they were targeted solely because of their religion. The more likely explanation for the surveillance was a desire to locate budding terrorist conspiracies. The most obvious reason for so concluding is that surveillance of the Muslim community began just after the attacks of September 11, 2001. The police could not have monitored New Jersey for Muslim terrorist activities without monitoring the Muslim community itself.

But as Samuel Bagenstos, a law professor at the University of Michigan and former official in the civil rights division of the Justice Department, told MSNBC’s Adam Serwer, that’s not the way it works. For instance, he said, “A police department cannot specifically target African-Americans for surveillance on the ground that the department is seeking to identify crime within the black community.”

The case, Hassan v. City of New York, was filed by Muslim Advocates and the Center for Constitutional Rights, on behalf of a broad group of American Muslims, including a decorated Iraq war veteran and the former principal of a grade school for Muslim girls.

“In addition to willfully ignoring the harm that our innocent clients suffered from the NYPD’s illegal spying program, by upholding the NYPD’s blunderbuss Muslim surveillance practices, the court’s decision gives legal sanction to the targeted discrimination of Muslims anywhere and everywhere in this country, without limitation, for no other reason than their religion,” Center for Constitutional Rights legal director Baher Azmy said in a statement. “It is a troubling and dangerous decision.”

“The fight is not over by any means. The surveillance program violates the Constitution, and we are confident that this decision will not hold up to review upon appeal,” Glenn Katon, legal director of Muslim Advocates, said in a statement.

I really hope this decision doesn’t stand,” the lead plaintiff in the suit, Syed Farhaj Hassan, an Iraq war veteran, told the New Jersey Record. “I have dedicated my career to serving my country, and this just feels like a slap in the face — all because of the way I pray.”