Robert Downey Jr's son Indio pleaded guilty to drugs charges in court today - but was encouraged to stay clean by a judge, who said he's in an unusual situation because he's 'connected' to Iron Man.

Indio Downey, 21, appeared in court - supported by his actor father - after being charged with felony drug possession in June.

He pleaded guilty to felony cocaine possession, but the judge said the conviction can be wiped clean as long as he stays clean for 18 months and finishes his rehab program.

He was arrested for cocaine possession in West Hollywood, after reportedly being spotted smoking something out of a pipe in a vehicle he was a passenger in by police.

When stopped, officers found cocaine.

Speaking in court

The Hollywood actor's eldest child has also been charged with misdemeanour possession of drug paraphernalia, according to gossip website TMZ.com.

Downey voluntarily checked himself into rehab two months ago, and speaking to the youngster, Judge Keith Schwartz said: "You are doing an excellent job so I'm glad to hear that."

He added: "Its a 24-7 disease, it can crop up at any time," and asking if he can cope with that, Downey replied: "Yes sir."

But bizarrely, the judge then encouraged Downey to beat drugs, by saying: "I know in life people always look up to superheros, but I think you might have contact or an inside as to one superhero - that's Ironman."

He agreed with the judge throughout

He then urged the star's son to make new friends who would be a better influence on him, saying: "Thats a lifestyle change you have to make, you have to find new friends, friends who are concerned about your lifestyle, your health."

As Downey is a first time offender, he was automatically entitled to a drug diversion program.

Robert, who previously battled drug addiction himself and was arrested numerous times in the 1990s on drug-related charges, thanked the LA County Sheriff's Department for "their intervention" at the time of his son's arrest.