Java News from Monday, May 16, 2005

jutils.com has released lint4j 0.8.1, a free-beer "static Java source code analyzer that detects locking and threading issues, performance and scalability problems, and checks complex contracts such as Java serialization by performing type, data flow, and lock graph analysis." Version 0.8.1 adds a Maven plugin, new Ant templates, and fixes bugs. I tested this out on the XOM code base. Most of what it reported as questionable were areas where I knew exactly what I was doing and had a good reason for doing it. However, there was one surprise. It5 flagged a couple of places where I was calling StringBuffer.setLength(0). I had assumed this would be faster than creating a new buffer, but according to lint4j:

The init() method throws away its internal buffer and allocates a new one of size 16, even if it was created with a larger initial size. This can introduce unexpected performance problems as explained in the last section. In some implementations the original char array is overwritten with a zero value, which takes a lot more time for larger data sets than just throwing it away.

Solition [sic]: create a new StringBuffer instead of using StringBuffer.setLength()

In my case the data is quite small, so I don't think I'm going to make the change. Still, it's something to think about.

lint4j also warned me that "Strings should be compared using equals() even if intern()ed." Apparently, "In Java JDK 1.3 and later, the method String.equals() tests for reference equality before testing the more expensive by-value equality, so there is no performance improvement when the == operator is used, it just makes the code harder to maintain and to get correct."


Websina has released BugZero 4.0.3, a $1299 payware (+$300 for maintenance) Web-based bug tracking system that supports multiple projects, group-based access, automatic bug assignment, file attachment, email notification, and metric reports. Bug Zero is written in Java and can run on top of various backend databases including MySQL. 4.0.3 is a bug fix release.