Judge Christopher Rose said an array of EU food quality standards had not been given proper legal standing and were thus "unknown to law".
'Bananas' EU rules
Bananas must not bend abnormally
Bananas should be at least 5.5in long and 1.05in round
Peaches below 2.2in diameter must not be sold between July and October
Carrots must be 0.75in wide, apart from baby carrots
He said the standards could therefore not be used to prosecute a branch of supermarket chain Asda.
The EU's rules, frequently pilloried in the UK media, are aimed at upholding food standards across member states.
The Department for the Environment, Food and Rural Affairs (Defra) took Asda to Portsmouth magistrates court last November over 14 alleged breaches of EU rules.
The case was thrown out by the judge, who said British domestic law had not been changed to keep up with the EU regulations.
Defra appealed to the High Court, where the judges upheld the earlier ruling.
The 14 charges against Asda's store in Fareham, Hampshire, included claims that some Iceberg lettuces were damaged, some aubergines were not fresh or clean and oranges, plums and lemons carried no country of origin or quality class.
Confusing cucumbers
Defra also said some clementines had no class information and cooking apples were not marked with their variety. Asda denied the charges.
The supermarket chain had a run-in over the rules in 2000, when it urged the EU to reconsider applying its "confusing" regulations on cucumbers.
Rule 1677/88 said a cucumber could only be given a premium Class 1 label if it curved less than 10mm every 10cm - so in 1998 Asda had to relabel its curvy organic cucumbers class 2.
The judge said that this time Asda had been charged under the 1964 Agriculture and Horticulture Act, as amended in 1972.
But the charges related to alleged breaches of European regulations made between 1981 and 1999, which therefore post-dated the Act.
Lord Justice Rose agreed only those grading rules which were in force in 1972 could be the subject of any criminal sanction under the 1964 Act.
The alleged offences with which Asda was charged were therefore "unknown to law", he decided.
Law change due
Defra can appeal to the House of Lords, but if that fails, the government will have to change the law to give legal effect to the rules.
"There was no crusade by Asda," said a spokesman for the chain.
"We simply had our doubts about whether criminal charges could be brought."
A spokesman for Defra said urgent moves would be considered to ensure that the EU regulations were properly brought into force.
He said: "We are looking to remedy the law as quickly as possible.
"This case has revolved around a fairly narrow point of law."