SAN FRANCISCO — A federal judge Tuesday ruled that a California law barring IMDb from publishing actors’ ages violates the First Amendment, and said the statute also fails to address a deeper problem of sex discrimination in Hollywood.

In an order granting IMDb’s motion for summary judgment against Assembly Bill 1687, U.S. District Judge Vince Chhabria of the Northern District of California wrote the law is a “direct restriction” on factual speech. He also wrote the law is “not narrowly tailored” or “actually necessary” to combat age discrimination against older actors.