Today the pain is entirely with the ex-boyfriend, 22-year-old undergraduate Liam Allan; a man of good character

The text message was explicit and unequivocal. ‘No pain without gain,’ the young woman boasted to a friend.

She was referring enthusiastically to a sexual act she had performed with a former partner who had ended their relationship. She had ‘begged’ him to take her back, but he wasn’t interested. She ‘pestered’ him for casual sex, other digital messages made clear. Still he had refused.

Today the pain is entirely with the ex-boyfriend, 22-year-old undergraduate Liam Allan; a man of good character.

It is only by luck rather than the proper, statutory, functioning of the criminal justice system, that Mr Allan is not beginning a substantial prison sentence for multiple rapes and a sexual assault, and a life-long presence on the sex offenders’ register.

This is an extraordinary and troubling case; one which goes to the heart of the controversy surrounding Britain’s rape laws and the policy-shaping role of Director of Public Prosecutions Alison Saunders, head of the Crown Prosecution Service, who only recently suggested that a rape acquittal did not mean the alleged victim was not telling the truth. Her growing number of critics see the issue as a matter of political correctness versus common sense. Already under-resourced, the system is being pushed to deliver on ideologically driven target figures rather than blind justice.

What then of the catalogue of failures that almost ruined the life of an innocent man? The sequence of events is chilling.

Mr Allan had spent two years on bail and was charged with the serious sex offences in March. He had been suspended from his job which pays towards his university education. Much more than that hung in the balance. But on Thursday his trial at Croydon Crown Court collapsed when it emerged ‘at the 59th minute of the 11th hour’ that a cache of some 40,000 texts and social media messages sent by his former lover turned accuser, and downloaded on to a disk by police two years ago, had not been disclosed to the defence by the investigating officer.

Mr Allan’s defence counsel Julia Smart was handed 2,400 pages of transcripts of the phone messages only after the complainant had given her evidence from the witness box when the case opened two weeks ago

Nor had the police given the CPS or the prosecuting counsel at trial sight of the material. That in itself was very wrong.

Far worse – and threatening a serious miscarriage of justice – was that the messages, many sent on platforms such as WhatsApp and Snapchat, presented an ‘entirely contrary’ version of the accuser’s sexual and emotional relationship with Mr Allan to the one she had given to the police and in court.

Mr Allan’s defence counsel Julia Smart was handed 2,400 pages of transcripts of the phone messages only after the complainant had given her evidence from the witness box when the case opened two weeks ago.

His defence team had been pressing for access to the phone records but were rebuffed by the police on grounds that there was nothing of material interest to the case.

Last night, prosecuting counsel Jerry Hayes said that he had asked the investigating officer – believed to be a detective constable – about the existence of the disk only when Miss Smart had pressed him on it during the trial. Mr Hayes had been appointed to the case only at the start of the trial.

‘Police officers do not seem to understand their duties of disclosure,’ Mr Hayes, a former MP, told the Mail last night. ‘They have a statutory duty to look at everything – not just the bits that will help the prosecution. They should log all the material and then send it up to the CPS lawyer handling the case. That did not happen here.

‘The first thing I knew about [these messages] was when we were halfway through the trial. The defence counsel asked if I was sure there was no digital download from the complainants’s phone.

‘She said, “Are you sure there’s nothing there?” I said I would check. I asked the officer if he had the disk of phone material.

‘“Oh yes,” he said. But he said it was clearly not disclosable, as some of it was very private.

‘I asked him if there was anything on the disk which could undermine the prosecution case. “No,” he said.’

This was clearly nonsense. A nonsense that would have put Mr Allan behind bars for a long time.

Mr Hayes said that, having learned the disk existed, he had a duty to serve the material to the defence. The trial was adjourned until this week.

Miss Smart sat up into the small hours examining the undisclosed evidence. It was worth the sleepless night. What Miss Smart found in the time available was only ‘the tip of the iceberg’ but turned the case on its head.

Mr Hayes said yesterday that he agreed with Miss Smart that the messages were ‘devastating’ to the prosecution case.

The wider impact on the way the investigation and prosecution of rape in Britain remains to be seen.

On Thursday, Judge Peter Gower found Mr Allan not guilty on all charges, after Mr Hayes had apologised to the student on behalf of the prosecution, which offered no evidence against him.

‘There is something that has gone wrong and it is a matter that the Crown Prosecution Service, in my judgment, should be considering at the very highest level,’ said the judge.

‘Otherwise there is a risk not only of this happening again but that the trial process will not detect what has gone wrong and there will be a very serious miscarriage of justice. He leaves the courtroom an innocent man without a stain on his character.’

It is hard as yet to gauge the mindset or motives of the investigating police officer involved. But he seems at best to have gone about the task as if the messages did not ever exist

The judge said that police must tell prosecutors about all material collected during their investigations. ‘It seems to me to be a recipe for disaster if material is not viewed by a lawyer,’ he said. ‘Something has gone very, very wrong in the way this case was investigated and brought to court.’ Indeed it had.

More than 200million texts are sent in the UK every day. It is the communication of choice for the younger generation. It also leaves an unambiguous digital trail.

It is hard as yet to gauge the mindset or motives of the investigating police officer involved. But he seems at best to have gone about the task as if the messages did not ever exist. Mr Hayes told the court: ‘It appears the officer in the case has not reviewed the disk, which is quite appalling.’ Incompetent, certainly.

Inevitably, the role of Mrs Saunders and her campaign to increase the number of rape prosecution and convictions looms large.

According to the latest statistics, sex attacks recorded by police are at a record high of 129,700 – an average of about one every four minutes.

Rapes rose by about 22 per cent in the year to June to 45,100, while other sex offences rose by 17 per cent to 84,600 – the highest level since records began in 2002.

Experts say that the rise was partly because victims were more willing to report attacks – including historical ones – and police are more likely to take complaints seriously since the Jimmy Savile sex-abuse scandal.

Convictions rose from 2,689 in 2015–16 to a record 2,991 in 2016–17 – up 11 per cent. But unsuccessful prosecutions also increased from 1,954 to 2,199 over the same period – a rise of 12 per cent.

Mrs Saunders has made a number of incendiary statements on the subject. In 2015, she advised that women who wake up in a man’s bed with no recollection of the night before should seek advice from a rape counsellor.

In August, she said prosecutors should examine alleged rapists’ past sexual behaviour and treatment of women as part of efforts to increase conviction rates.

In October, she claimed that acquittals in rape cases where the victim was drunk do not necessarily mean that they made a false allegation to police. The DPP pointed to research suggesting that malicious claims are made in less than 1 per cent of rape cases.

But critics said her comments raised a question mark over the innocence of rape suspects cleared by a jury and lent credence to the notion that there was ‘no smoke without fire’ in unproven allegations. Mr Allan now feels forced to defend his good name again by speaking to as many news outlets as possible.

As the law on anonymity for rape accusers dictates, the world is left knowing far more about the wronged defendant than the false accuser. Mr Allan will hope to be able to pick up the pieces and get on with life.

His sexual history – real or imagined – has been picked over in public in minute detail.

Then there is the taint of having been charged with multiple rape and assaults in the first place – something which, with human nature and the internet being what it is, he will not necessarily be allowed to forget.

The CPS will now conduct a ‘management review’. The Met said there would be an ‘urgent assessment’ by the force. Too late for Mr Allan – and of no service at all to the real victims of male sexual violence.