A senior judge has blasted a detective and the Crown Prosecution Service for their handling of a gang rape case that saw four young men put through two years of hell before they were finally cleared.
At Gloucester Crown Court, Judge Jamie Tabor QC said Detective Constable Ben Lewis got too close to the complainant and did not understand his job properly.
This led to "stark and very serious omissions" by the officer in failing to disclose "game changing" evidence.
The officer now faces an inquiry by Gloucestershire Police's professional standards department and could face disciplinary action.
Judge Tabor said that had Thady Duff, Leo Mahon and Patrick Foster, all 22, and James Martin, 20, been found guilty and this evidence later emerged he was certain the Court of Appeal would have found the convictions unsafe.
The four men had been accused of the gang rape of a young woman at an annual college ball at the Royal Agricultural University in Cirencester, Gloucestershire in May 2014.
She claimed she was subjected to violence, including strangulation, and some of it had been filmed and then sent by Mr Duff to his friends via Snapchat.
The trial was due to begin at Gloucester Crown Court in March but after delays due to the late disclosure of evidence and a review of the case, the prosecution offered no evidence and the four defendants were cleared.
Afterwards the defendants' barristers criticised Det Con Lewis for "cherry picking" supportive evidence and "airbrushing out of the picture" anything that could have helped the men.
This included text messages sent by the complainant in the hours after the alleged incident and a conversation with a friend about what would happen if the video became common knowledge.
The mobile telephone evidence was only recovered when experts instructed for the defence carried a full examination of the device.
It also emerged as the trial was due to begin that police failed to disclose that the complainant was a witness to an alleged rape on an army base in October 2014 and that there were inconsistencies in her evidence. The alleged rapist was a soldier but he was later cleared.
Three of the defendants, Mr Duff, Mr Mahon and Mr Foster, returned to court last month to apply for a proportion of their legal costs to be paid by the prosecution. Mr Martin received legal aid in the case.
They have been left with legal bills totalling £221,000 after hiring three QCs to lead the fight to clear their names.
Judge Tabor, The Recorder of Gloucester, granted the application and sent the case to a costs judge to determine the final figures payable.
He criticised DC Lewis for his shortcomings in examining the complainant's mobile phone and said he had a "limited grasp of responsibilities" as disclosure officer.
"Aware as he was, not only of his duties, but the character of the complainant, Det Con Lewis should have investigated the download from the telephone in far greater detail than he did," he said.
Three days before the trial was due to start, Det Con Lewis told the Crown Prosecution Service that "nothing of relevance had emerged" from a search of the telephone.
"This was a truly startling state of affairs," the judge said.
"Had not the applicants carried out a thorough investigation of the telephone a much skewed picture would have been presented to the jury."
He also criticised the detective for getting too close to the complainant, failing to properly record his dealings with her, and for a lack of training.
"The lack of training for the role of disclosure officer and identifying too closely with the complainant very nearly led to the applicants conducting their trial with one hand tied behind their back," he said.
"His omissions in relation to the disclosure of the telephone evidence were stark and very serious. His failure to adequately record meetings and conversations with the complainant was also a serious omission.
"If ever there was a case where the role of disclosure officer was separated from that of Officer in the Case, this was it."
The judge also blasted the Crown Prosecution Service for failing to obtain from the Royal Military Police the files of the case in which the complainant was a witness.
"I appreciate that hindsight can make great sages of us all but the failure to check what Det Con Lewis had carried out with regard to the downloaded material, and more importantly to do nothing about the Royal Military Police file for months was stark and wrong.
"But for that short entry in Det Con Lewis's notebook of October 20 2014 the defence would not have known about this at all.
"I have no doubt that Det Con Lewis's conduct in relation to the failure to examine the downloaded material amounted to improper act or omission.
"Other than the video clips, the prosecution's decision to offer no evidence was entirely as a result of the information uncovered by the defendants' investigation into the download of the complainant's telephone and their insistence that the Royal Military Police material be properly examined.
"The Crown Prosecution Service and Det Con Lewis must bear joint responsibility for the failure to properly disclose this game changing material."
Mr Duff, of Blunsdon, Swindon; Mr Foster, of Colchester, Essex and Mr Mahon, of Cirencester, Gloucestershire were not present in court.
A police spokesman said the force took "very seriously" the judge's findings.
"We accept the judge's findings and are now reviewing his comments in conjunction with the CPS to learn the lessons of this case and to improve how we investigate such cases," he said.
"It is of course the case that although the judge has identified failings in relation to the disclosure process it is right to note that Det Con Lewis has not been found to have acted in bad faith in any way.
"Further the officer was available and willing to give evidence at the costs hearing but was never provided with any opportunity to do so to answer any of the allegations made against him.
"The force shall refer the judge's findings to the its professional standards department who shall consider whether or not any conduct issues have been identified in relation to any officers and these will be assessed in conjunction with the Independent Police Complaints Commission if necessary.
"Even if no misconduct is found to have occurred the performance of individual officers may still require scrutiny under relevant force procedures."