LingPipe is (X)Lint Free

by

What a difference one line makes in the Java compiler. By setting the compiler flag -Xlint:all, (in ant, <compilerarg value="-Xlint:all"/>), you see all the compiler warnings which don’t cause outright errors.

The notion of checking a program for “lint” derives from the Unix utility lint, which operated on C programs.

With javac, lint checking includes deprecation (finds deprecated methods without @Deprecated attributes), unchecked (finds questionable uses of type casting and generics), fallthrough (finds fall through cases in switch statements), path (don’t know what this does — didn’t have any of those errors), serial (finds serializable classes without a serial version ID), and finally (also a mystery).

We had thousands of errors. Luckily, sometimes a fix takes care of dozens of errors in one line. It’s taken me three days to fix them all or verify they were right and suprress the warnings (some switch statements and some safe casts the compiler couldn’t verify). But it’s done.

Joss Whedon is my Master Now T-Shirt

I was mainly trying to follow master’s most excellent advice from the second edition of Effective Java. In fact, Joss Whedon Josh Bloch is my master now (and has been since the first edition; I’ll buy the t-shirt if someone makes one up). This is absolutely the best book for taking your Java code to the next level. (After you’ve digested it, check out Brian Goetz et al.’s Java Concurrency in Practice, of which Bloch’s a co-author, for some real mental gymnastics.)

I made the mistake had the opportunity to read the second edition after I gave it to Mitzi for Christmas [no, I’m not that much of a Grinch — we both pick gifts we’ll both enjoy; she got me some killer Volnay and I also got her some Nortec beats).

It found lots of places where I was naughty and forgot to put in serial versions for compilation (needed for forward compatibility). Most of the warnings had to do with unchecked type conversions. There I was just lazy when I converted to generics for release 3.0. I generified everything I could find that was causing warnings, suppressed warnings for necessary casts and array allocations (the type system isn’t perfect), and am now much more confident that things are working right on the inside.

What does this buy the LingPipe user? Well, you won’t get any warnings if you turn lint on and compile LingPipe now. You can bask in the glow of the warm fuzzy feeling I have for a compilation well done. I don’t think I changed a single bit of behavior (except protecting against forward compatibility errors from changing method signatures) with this exercise.

2 Responses to “LingPipe is (X)Lint Free”

  1. jeffdalton Says:

    Nice post, I didn’t know about the compiler setting.

    I love the attention to detail. Did any of the ‘warnings’ help you find defects?

    Good recommendation on Effective Java by Josh. It’s one my favorites.

  2. lingpipe Says:

    The serialver warnings helped. I’d forgotten to put those in places, and that I consider a real defect.

    The unchecked warnings didn’t help me find any defects per se. I think they’ll help more in development going forward, though.

    There are interfaces and implementations that I’d change from arrays to List instances to cut down on the number of casts of arrays I had to do. Ironically, I was using arrays in Java 1.4 because it gave me some degree of type safety in the external API that wasn’t available in the bare List interface. I didn’t want to return untyped List objects when I knew what type of objects they held. As of 1.5, the generics let me use the collections type safely.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s