Judge Andrew Napolitano said New York officials cannot go after President Trump's tax returns "based on hatred."

Speaking on "Fox & Friends" Thursday, which was broadcasting live from the USS New York, Napolitano weighed in on the constitutionality of a new law, which could lead to the release of the president's state taxes.

"If the statute was written because Democrats in the state of New York hate the president and want to find a way to invade his privacy or interfere with his presidency, he must challenge the statute and he will prevail," said Napolitano, adding the Supreme Court "has never upheld a statute based on hatred."

The New York legislation would lift an existing state restriction on revealing an individual's tax returns. It says the state Commissioner of Taxation and Finance shall release those returns if requested by the House Ways and Means Committee, Finance Committee, or Joint Committee on Taxation.

DEM WANTS TRUMP OFFICIALS JAILED FOR NOT TURNING OVER TAX RETURNS

Earlier versions of bills in the New York State Senate and Assembly allowed for the request of any New Yorker's tax returns, but on Wednesday, amendments passed that narrowed the scope to tax returns of certain officials including the president, vice president, members of Congress representing New York, and others.

If Democratic Gov. Andrew Cuomo signs the bill into law, Congress would be able to request someone's individual's tax returns from any year, as well as business tax returns for entities in which they have at least a 10 percent voting share.

TRUMP BLASTS 'HIT JOB' NEW YORK TIMES REPORT ON LOSSES IN TAX RETURNS

The host of Fox Nation's "Liberty File" said the original version of the legislation targeted Trump, but a lawyer advised lawmakers to make it broader so they could have "plausible deniability."

"What legitimate governmental purpose is served to the state of New York by selectively exposing the private tax returns of one of its taxpayers?" he asked.

Napolitano said the state of New York will have a high legal bar to clear if the law is challenged on the basis that it targets Trump.

Fox News' Ronn Blitzer contributed to this report.