[JSR308] A little prototype experience...

Neal Gafter gafter at google.com
Fri May 4 16:39:35 EDT 2007

I've had a chance to look at and play with the spec and prototype, and I
have a few comments.

The first sentence of the introduction of the design document says:

We propose an extension to Java's annotation system [Bra04a] that permits
annotations to appear on any use of a type.

This is repeated elsewhere in the spec:

Our system extends Java to allow annotations on any use of a type. Our
system uses a simple prefix syntax for type annotations: the annotation
appears before the type, as in @NonNull String.

In general this is ambiguous (how do you annotate the type part of a
qualified identifier), but the spec gives no syntactic disambiguation.
Instead, the specification selects a number of uses of types in the Java
grammar, and describes by example how an annotation will be supported in
that context. The implementation does not support annotations on all uses of
types either. I've listed a number of specific contexts which aren't handled
properly in a previous email, but to make my point concrete here is one
example for which the prototype gives a syntax error:

        f(@Foo int.class); // annotation on the type int

We should align the spec with itself by either describing our goal as
providing support for annotations on selected contexts in which types may be
used in Java programs, or alternately modify the spec and implementation to
support annotations on all uses of types, as the introduction implies. I
prefer we support annotations on all uses of types, and I believe it would
be straightforward to introduce a syntax that is complete, unambiguous
(unlike the current syntax), and intuitive.

I was unable to build the @NonNull checker, but I believe null checking
cannot be done statically in Java, even with user annotations. Once I get
the checker working I'll demonstrate with a small program that throws a
NullPointerException on the use of a variable whose type was annotated
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.csail.mit.edu/pipermail/jsr308/attachments/20070504/1e108691/attachment.html

More information about the JSR308 mailing list