It seems to me that the lesson is to stop using Java. :-)
Though, in truth, while I think Java has several misfeatures that make it prone to ugly code, I don’t think ugly code is really the fault of Java. I blame most of the problems I see in Java on the culture surrounding it.