Problem with when type annotation positions are determined

Jonathan Gibbons jonathan.gibbons at oracle.com
Wed Dec 5 17:20:09 PST 2012


Werner,

It seems to me there are problems arising from these lines at the end of 
Enter

             annotate.enterDone();

             for (JCCompilationUnit tree : trees) {
TypeAnnotations.completeTypeAnnotationsInSignatures(this.names, tree);
             }

At least conceptually, the for-loop calling 
completeTypeAnnotationsInSignatures should logically be done inside 
annotate.enterDone, not after it.  Code in enterDone will be analyzing 
annotations, including repeated annotations, and will presumably trip up 
over type annotations.

Separately, very minor, it looks like TypeAnnotations should be an 
instance obtained from a Context -- that would save you having to pass 
in a Names.

-- Jon

On 12/01/2012 03:23 PM, Werner Dietl wrote:
> Joel, Jon, all,
>
> the trunk version of type-annotations passes the jtreg tests and also
> the Checker Framework tests.
> However, some uses of the compiler failed and I finally managed to
> produce a minimal test case.
> This problem is caused by the changes I made to when the type
> annotation positions for different annotations is determined, i.e.
> where we call com.sun.tools.javac.code.TypeAnnotations.completeTypeAnnotationsInSignatures
> in Enter/MemberEnter/Attr.
> Previous versions (e.g. the code that is still in jsr308-langtools)
> did not have this problem.
>
> To reproduce:
>
> 1. tar -xvzf annobug.tar.gz
> 2. cd annobug
> 3. type-annotations-build-dir/bin/javac -cp . Main.java
>
> For me, this results in a stack trace that begins with:
>
> java.lang.NullPointerException
>          at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.setTypeAnnotationPos(TypeAnnotations.java:789)
>          at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.findPosition(TypeAnnotations.java:862)
>          at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitAnnotatedType(TypeAnnotations.java:839)
>          at com.sun.tools.javac.tree.JCTree$JCAnnotatedType.accept(JCTree.java:2304)
>          at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
>          at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:450)
>          at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
>          at com.sun.tools.javac.tree.TreeScanner.visitClassDef(TreeScanner.java:80)
>          at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:648)
>          at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
>          at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:450)
>          at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
>          at com.sun.tools.javac.tree.TreeScanner.visitTopLevel(TreeScanner.java:68)
>          at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:517)
>          at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
>          at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:450)
>          at com.sun.tools.javac.code.TypeAnnotations.completeTypeAnnotationsInSignatures(TypeAnnotations.java:87)
>          at com.sun.tools.javac.comp.Enter.complete(Enter.java:514)
>          at com.sun.tools.javac.main.JavaCompiler.complete(JavaCompiler.java:791)
>          at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:2425)
>          at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:2332)
>          at com.sun.tools.javac.code.Symbol.complete(Symbol.java:426)
>          at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:834)
>          at com.sun.tools.javac.jvm.ClassReader.loadClass(ClassReader.java:2513)
>
>
> Note that if the classes are compiled together, no problem arises, i.e.
>
> javac *.java
>
> works as expected. Also, compiling the classes in the right sequence works:
>
> javac -cp . Anno.java
> javac -cp . Dep.java
> javac -cp . Main.java
>
> In the invocation that gives an exception we're trying to determine
> the position for an annotation that doesn't have its TypeCompound set
> yet.
> I failed at tracking down why the TypeCompound is set when invoked
> with all classes, but not when invoked with just one.
>
> Ideas?
>
> Thanks,
> cu, WMD.
>



More information about the type-annotations-dev mailing list