David Eliadze (20) flashed the officers on a city centre street after punching a notice board at a garda station following a public order arrest.
Dublin District Court heard he had since turned to religion for direction in his life.
Judge Patricia Cronin struck the charges out, sparing him a criminal record after he made a €200 charity donation.
Eliadze, of Whitechurch Way, Ballyboden, pleaded guilty to threatening, abusive and insulting behaviour and garda obstruction.
Garda Sergeant Mary Brophy said a large group of youths were drinking alcohol at Temple Bar Square on June 1, 2019.
They began shouting at gardaí, calling them "pigs".
The accused continued to be abusive and aggressive when the gardaí spoke to him.
He refused to empty out his alcohol, resisted arrest and tried to flee gardaí who had to place him on the ground.
When released from custody at Pearse Street garda station, Eliadze refused to leave and became aggressive in the public office, where he punched the notice board.
Gardaí followed him outside where he lowered his shorts, exposing his rear to them before turning and exposing his penis. He was arrested again, on D'Olier Street.
Eliadze had no prior convictions and had just turned 18 at the time, his lawyer said. He had young brothers who looked up to him and he wanted to be a good role model to them.
Eliadze apologised for his "appalling conduct".
He no longer took alcohol.
The judge told him it was "entirely unacceptable behaviour" and if the accused wanted to be a role model to his brothers "I don't think they would be very proud to see your behaviour on that day.
"It's not what you would expect a role model to do."