Running on Java 22-ea+27-2262 (Preview)
Home of The JavaSpecialists' Newsletter

077"Wonderfully Disgusting Hack"

Author: Dr. Heinz M. KabutzDate: 2003-09-02Java Version: 1.4Category: Software Engineering

Abstract: In the early days of Java, the Sun Microsystems engineers still had the freedom to write hilarious comments into their code.


Welcome to the 77th edition of The Java(tm) Specialists' Newsletter. I sent out a newsletter last week to see who preferred text over HTML, especially regarding SPAM filters. Due to the public outcry at the suggestion of moving away from HTML, I will in future send all newsletters as HTML. Please change your SPAM filters to receive emails from my email addresses.

I am sitting in a hotel room in a stunning little town in Switzerland called Zug whilst my daughter is celebrating her second birthday today. My voyage began on Saturday afternoon from Cape Town to Johannesburg, and on towards Zurich. My suitcase had other ideas. He liked Johannesburg quite a lot, and together with the other suitcases from the flight, decided to stay overnight and then instead travel to Paris, go on a tour of the Eiffel tower, meet some pretty lady suitcases, etc. He arrived last evening at my hotel door, looking rather bedraggled, with an accusing look on his face: "Why didn't you call?" he told me as he walked through the door. He amused himself by the look of his owner squashed into a one-size-too-small shirt that belonged to our Swiss customer. "What's with the shirt?!" he had the audacity to exclaim. If he thinks he is coming with to China, he has another thing coming! Please visit our new self-study course catalog to see how you can upskill your Java knowledge.

"Wonderfully Disgusting Hack"

People sometimes ask me how I find out the things that I write about in my newsletter. The answer is that I don't know how. It is pretty much a random walk through the JDK source code that gets me the best results.

Last night, whilst my suitcase was screaming through the air at 30'000 feet, I spent some time reading through a new release of the J2EE Core Patterns book. Whilst I was reading it, I was getting more and more agitated with the way that exceptions were being handled. You know I am not a fan of checked exceptions, and in a future newsletter will expound on this. I got sidetracked from reading the book, and ended up reading up on how java.awt handles exceptions. During these explorations, I stumbled across a comment in the java.awt.Toolkit class in JDK 1.4.2 that is simply priceless. It goes like so:

    static boolean enabledOnToolkit(long eventMask) {
        // Wonderfully disgusting hack for Solaris 9

Is that not cute? To write that in code that you know could possibly be read by 3'000'000 Java developers around the globe takes a lot of chutzpah.

I did a search on the classes in the JDK 1.4.2 and found 45 classes that contained the word "hack". A great portion of these are from org.apache.* packages, but the majority is from code by Sun Microsystems.

Now the magic question: Am I worried? I am trying to build software for major industry players on top of a basic platform that contains 45 classes with documented hacks! Perhaps I should be worried - but I am not. What is worse than knowing you are an idiot? Worse is thinking you are not a dolt, but actually, being one.

Therefore, here are some reasons why I feel more comfortable than ever to write industry-strength code on top of Sun's JDK:

  1. All software contains hacks.
  2. I would prefer to know about them.
  3. Only a real developer would write "hack" into his comments.
  4. I am therefore more comfortable using Sun's JDK than some black-box proprietary solution with hundreds of undocumented hacks.

This is a really short newsletter, just to get this topic off my chest. Do yourself a favour and look at the source code of java.awt.Toolkit in JDK 1.4.2. I think you will enjoy it :-)

Warm regards from Switzerland, and my suitcase also says "hi".




We are always happy to receive comments from our readers. Feel free to send me a comment via email or discuss the newsletter in our JavaSpecialists Slack Channel (Get an invite here)

When you load these comments, you'll be connected to Disqus. Privacy Statement.

Related Articles

Browse the Newsletter Archive

About the Author

Heinz Kabutz Java Conference Speaker

Java Champion, author of the Javaspecialists Newsletter, conference speaking regular... About Heinz

Superpack '23

Superpack '23 Our entire Java Specialists Training in one huge bundle more...

Free Java Book

Dynamic Proxies in Java Book
Java Training

We deliver relevant courses, by top Java developers to produce more resourceful and efficient programmers within their organisations.

Java Consulting

We can help make your Java application run faster and trouble-shoot concurrency and performance bugs...