SAN FRANCISCO — A federal judge tossed a securities class action on Thursday that slammed Hewlett-Packard Co. for touting its code of conduct even as its former CEO became embroiled in an ethics scandal.

U.S. District Judge Jon Tigar granted HP’s motion to dismiss a putative class action that reached back to the fall of former HP CEO Mark Hurd, who resigned in 2010 after a contractor claimed Hurd made inappropriate sexual advances toward her. Plaintiffs alleged that HP misled investors by adopting a new ethics code without disclosing Hurd’s missteps.