JSR 305

It's nice to see that the old idea of opening a JSR for standardizing the IDEA annotations for static error detection is moving forward (http://jcp.org/en/jsr/detail?id=305). It's especially nice to see that it isn't limited to the existing annotations (@Nullable, @NotNull, @NonNLS), but is going farther, to include concurrency and effects-based annotations. The temptation to fight through the necessary bureaucracy here at work to apply for the Expert Group is very high. Failing that, I figured I'd offer a couple of ideas here, to whomever the JetBrains contact on the EG turns out to be.

1)Method ordering/class protocol annotations. Many classes have either required or proscribed sequences in which methods should be executed. Annotations describing acceptable sequences would allow static analysis to cover issues like "Stream should be opened in a try block and closed in the finally block", and "Don't call stream.write() after stream.close()".

2)Swing event thread annotation. It should be possible to mark that a method should only be called in the Swing event thread, allowing misuses to be detected statically. Contrariwise, you'll need to be able to mark Runnable method parameters as executing in the event thread, to make this work with all of the various wrapper APIs which have been developed. (This would have the added benefit of prefenting many IDEA errors)

--Dave Griffith

2 comments
Comment actions Permalink

Thank you, Dave,

While I don't quite understand yet how the first proposal can be turned into annotation, and if this annotation is going to be lightweight enough to be included into standard set of annotations, the second one is definitely to be proposed to EG.

0
Comment actions Permalink

The first would probably have to be a set of protocol rule annotations. I've seen some academic work on this, and even a (unsuccessful) commercial product that did dynamic instrumentation of a set of protocol rules. I'll see if I can hunt up some links.

--Dave Griffith

0

Please sign in to leave a comment.