JDK-8145489 NPE in javac during Attribute stage. Sequel

Plizga Vladimir v.plizga at ftc.ru
Fri May 13 04:40:59 UTC 2016


Hello!

I'm the initiator of issue https://bugs.openjdk.java.net/browse/JDK-8145489 "NullPointerException while compiling certain annotations". The issue was closed because the assignee (Fairoz Matte) unfortunately couldn't reproduce it and I had no additional info by that moment.
But the bug is still actual for our project  and recently I researched it in detail. I've sent the results by email to Fairoz a week ago but I didn't receive any answer. Hope you can help me.

1. I've significantly simplified the code snippet to reproduce the bug. Now it consists of just 3 short Java files located in 'mypackage' package:

<File PackageAnnotation.java>
package mypackage;
public @interface PackageAnnotation {
  Class<?> classyAnnotationMember();
}
</File PackageAnnotation.java>

<File MyClass.java>
package mypackage;
public class MyClass {
  public class MyInnerClass { }
}
</File MyClass.java>

<File package-info.java>
@PackageAnnotation(classyAnnotationMember = MyClass.MyInnerClass.class)
package mypackage;
</File package-info.java>

An attempt to compile this files with javac 1.8.0_92 will end up with NullPointerException during Attribute stage (see the stacktrace in JDK-8145489).

2. The source of the error is condition “!env.next.tree.hasTag(REFERENCE)” in com/sun/tools/javac/comp/Attr.java:3335 line that was added in JDK 1.8.
AFAIU there is no enclosing environment for some class-type members of annotations at the topmost (package) level. That's why "env.next == null" and "env.next.tree" fails with NPE.

3. As a temporal workaround (in order to proceed with my current task) I’ve fixed the problem in 1.8.0_92 compiler’s source code by prepending the new condition with a naive checking for enclosing environment nullness:
   (env.next != null && !env.next.tree.hasTag(REFERENCE))
and rebuilt the compiler. This fix has not affected the amount of successfully passed tests run with jtreg and has allowed me to proceed. I believe Oracle engineers would find a truly proper way to fix it:)


I hope this information would be enough to reproduce and fix the bug. If not, you are welcome to request anything else.

Thanks,
Vladimir Plizga


More information about the compiler-dev mailing list