Now an appeal court in California has upheld the sentence for a homeless man who had fallen foul of the state's "three strikes" law, under which anyone committing three crimes is liable to spend between 25 years and life in jail.

Kevin Weber has served more than five years for the theft in 1995 of the four cookies, but a Santa Ana appeal court has decided he is a career criminal and the sentence should stand. He may not be released until 2021.

The case is the most extreme example of California's three strikes law since a man was jailed for 25 years in 1994 for grabbing a slice of pizza from some children. His sentence was reduced on appeal.

Weber had broken into a restaurant in Santa Ana through an air vent. The appeal court argued that had he not been caught when a burglar alarm was activated he would probably have stolen more items. "A safe-cracker who cracks an empty safe is nonetheless a safe-cracker," said Justice David Sills in a unanimous judgment.

"It shocks one's conscience to think that a man could spend the rest of his life in prison for stealing four cookies," said public defender Carl Holmes, whose office defended the homeless alcoholic. "For some unapparent reason the system still has no sense of compassion."

The case may be appealed to the supreme court on the grounds that a life sentence for the non-violent theft of four cookies is a cruel and unusual punishment. A plea for clemency may also be made to Governor Gray Davis.

Weber's previous offences include burglary, assault with a firearm and receiving stolen goods. He qualified for the sentence because he had committed three felonies which made him subject to the so-called Three Strikes and You're Out law, approved by California voters in 1994.

Critics of the law say there is no indication that it has reduced crime. Its supporters say it takes hardened criminals off the streets. The US jails 25% of all prisoners in the world although it accounts for only 5% of the world's population. There are 2m people in US jails, 400,000 of them for drug offences and 70% of them from racial minorities.