Using the Open-Sourced Java Platform


Having access to a system's source code is liberating. I've felt this since I first laid my eyes on the source code of the 9th Edition Unix in 1988, and I saw this again as I used the freshly open-sourced Java platform to implement a UMLGraph feature that has been bugging me for more than a month.

I've found that our freedom to explore a system's source code is a lot more important than two other often-cited benefits of open-sourced systems: their low (often zero) cost and our ability to modify them. I've explored this freedom to learn from a system's code in Code Reading and Code Quality. My point is that by having access to the code we're using we can become better and more effective programmers. Here is an example.

For some time I've been trying to modify UMLGraph so that its output could be directly piped into Graphviz dot, instead of going through an intermediary file. The trouble is that Java's javadoc, which UMLGraph uses, prints various notices on its standard output; these confuse dot. I looked for a solution in the javadoc API, but couldn't find one. Today, after I downloaded the open-sourced Java code, I decided to look at the problem again. By browsing an hour through the javadoc source code I found two solutions to my problem.

The procedure was remarkably easy. I first downloaded and unpacked Sun's Open JDK. I then searched for a file named javadoc. The two directories with that name were the places I used for greping through the code to find what I was looking for.

I first started looking for the javadoc message that I wanted to eliminate. I quickly located it (through an indirection of a property file), and saw that the method that used it contained a condition on a variable named silent. I found in the code that I could set silent through a public method, in order to remove the notice. However, through some more code browsing I quickly realized that silent would also hide all error messages, so I started looking for another approach.

I thus looked for references to System.out. These led me to a Messager [sic] class and a constructor that could independently specify the PrintWriter for warnings, errors, and notices. From there I found a way to programmatically invoke javadoc, with these objects as arguments. Now UMLGraph runs with the javadoc notices redirected to the standard error (where they should have been going anyway). Two days after the JDK open-sourcing and two hours after I downloaded it I was reaping the fruits of this new freedom.

Comments   Toot! Share

Last modified: Thursday, May 10, 2007 5:23 pm

Creative Commons Licence BY NC

Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.