Java Specialists' Java Training Europehome of the java specialists' newsletter

The Java Specialists' Newsletter
Issue 0772003-09-02 Category: Software Engineering Java version:

GitHub Subscribe Free RSS Feed

"Wonderfully disgusting hack"

by Dr. Heinz M. Kabutz

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!

NEW: Please see our new "Extreme Java" course, combining concurrency, a little bit of performance and Java 8. Extreme Java - Concurrency & Performance for Java 8.

"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".


Software Engineering Articles Related Java Course

Extreme Java - Concurrency and Performance for Java 8
Extreme Java - Advanced Topics for Java 8
Design Patterns
In-House Courses

© 2010-2016 Heinz Kabutz - All Rights Reserved Sitemap
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. is not connected to Oracle, Inc. and is not sponsored by Oracle, Inc.