Sergey Aleynikov’s five-year legal odyssey never should have begun, a judge has ruled, increasing the likelihood that the former Goldman Sachs computer programmer will be acquitted at his second trial for allegedly stealing the bank’s high-frequency trading code.

Aleynikov was arrested in 2009 His home was searched and a number of computers and other equipment seized.

But New York State Judge Ronald Zweibel said that the arrest was “illegal” and that the Federal Bureau of Investigation “did not have probable cause to arrest the defendant, let alone search him or his home.” As a result, Zweibel suppressed much of the evidence prosecutors planned to use against Aleynikov, including his first statements to the FBI, given before he was read his rights. Those are “the fruit of the poisonous tree” of the “illegal arrest,” Zweibel said. Later statements will be allowed into the trial, due to Aleynikov’s waiving of his right to counsel.

Aleynikov, who allegedly planned to deliver Goldman’s software to Teza Technologies, a controversial HFT firm founded by several former Citadel Investment Group traders that has not been accused of wrongdoing in the case, still must face the criminal charges, under which he faces four years in prison. Zweibel last May rejected his bid for a dismissal.

It will be Aleynikov’s second time before a jury: He was convicted in federal court of similar charges in 2010 and spent more than a year in prison before a federal appeals court threw out the guilty verdict. Zweibel said that Aleynikov’s computers should have been returned to him after that reversal, rather than handed over to the Manhattan District Attorney’s office.

“Justice Zweibel’s decision represents a damning indictment” of the case against Aleynikov, his lawyer, Kevin Marino, said. “We are confident that today’s decision is another important step on Sergey Aleynikov’s long journey to complete vindication.”