[Checkers] Q about new JSR 308 proposal

Michael Ernst mernst at csail.mit.edu
Thu Sep 4 15:24:51 EDT 2008

> __ My previous understanding __
> I thought that you would read a string array (even before using  
> annotations) as:
> declaration:        @English String  @NonNull [] @Length(10) []
> order of reading:   3--------------> 2---------> 1------------->
> So it would be "length-10 array of non-null array of English String."
> This is how I described it in the manual previously.

No, this is incorrect.  The outermost array type is the leftmost ("inside")
one in the written syntax.

If you execute

  new String[10][20]

then the result is a length-10 array, and each of its elements is a
length-20 array.  It is *not* a length-20 array of length-10 arrays.

Even Josh Bloch got this wrong when I gave it to him as a Java Puzzler of
my own, so you don't have to feel bad about your confusion.

> The new proposal now has the same problem it tries to solve.  Namely,  
> given the following declaration:
>    @English String @NonNull []   arr1,   arr2 @Length(10) [];
> In the proposed syntax, the types would be:
> arr1:   nonnull array                    of English string
> arr2:   nonnull array of length-10 array of English string

No, arr2 is a length-10 array of nonnull array of English string, for a
different reason than you thought:  in each component you read
left-to-right, like this:

    @English String @NonNull [] [] []  arr1,   arr2 @Length(10) [] [] [];
    3-------------> 2--------------->               1------------------>

Thanks for pointing out that I need considerably more explanation in the
document.  The Java array syntax is a mess to understand even before
annotations; my hope is that annotations don't make things any worse (or
any different), but unfortunately they do make people notice the existing
problems in the syntax.

Let me know whether this makes sense, and what I can do to explain it.


More information about the checkers mailing list