[JSR308] Custom annotations?

Michael Ernst mernst at mpi-sws.mpg.de
Thu Feb 7 08:14:17 EST 2008


Richard-

> I was able to get JSR-308 annotation checkers working fine.

Great!  I'm glad to hear that.


> My question is: how can I turn on type checkings relative to the annotations 
> @Rate and @Volatility I've defined?

Please see Section 8, titled "How to write a checker plugin", of the "JSR
308 Type-checkers and Framework" document, which is linked from the JSR 308
webpage (http://groups.csail.mit.edu/pag/jsr308/).

Here are direct links (but they're subject to change, so if at some point
they do not work, just follow the links from the main JSR 308 page).
The "JSR 308 Type-checkers and Framework" document is
  http://groups.csail.mit.edu/pag/jsr308/dist/manual.pdf
  http://groups.csail.mit.edu/pag/jsr308/dist/manual.html
Here's a direct link to Section 8, "How to write a checker plugin":
  http://groups.csail.mit.edu/pag/jsr308/dist/manual.html#writing-a-checker

You'll also find the distributed checkers helpful as examples (especially
the simple ones like Interned).

If you still have questions after examining these, please ask again, and
we'll do our best to help.


>     public static void main(String[] args) {
>         Main test = new Main();
>         test.allTests(); // Why I've got (defer.invalid) here??? <<<< =====
>     }

The checker outputs "deref.invalid", not "defer.invalid".
"deref.invalid" is short for "dereference.invalid", meaning that this
dereference (namely, invoking a method on the "test" variable) might throw
an exception at run time.

The reason for this is that the type of the "test" variable is "@Nullable
Main", meaning that it might be null.  You can change the declaration to
"@NonNull Main" to eliminate the checker warning.

You don't always have to write "@NonNull" for local variables that are
never null.  The checker deduces some such facts for you, and it should do
so in your example.  I've added it to our test suite so it will be corrected
in a future release.

                    -Mike



More information about the JSR308 mailing list