Tuesday, June 02, 2009

JSR308 (pluggable type checking) is looking promising

Watching the Twitter stream for JavaOne, I saw a number of folks say they were quite impressed with the talk called "Preventing Bugs with Pluggable Type Checking."  I checked out the link for JSR308, and this looks very promising.

Basically, you can add annotations that check for things such as NonNull or Nullable, and then incorporate a checker that supports these annotations into the compiler.

For example, you can say
import checkers.nullness.quals.*;

public class GetStarted {
    void sample() {
        @NonNull Object ref = new Object();
    }
}
and then say
javac -processor checkers.nullness.NullnessChecker GetStarted.java
and the checker will ensure that the @NonNull object indeed is not being set to null anywhere.
Take a look at the page for JSR308, this looks like a good new addition.

No comments: