RFR: 8204630: generating an anonymous class with Filer#createClassFile causes an NPE in JavacProcessingEnvironment

Jan Lahoda jan.lahoda at oracle.com
Tue Jun 12 14:13:36 UTC 2018


Hi Liam,

Thanks for looking at this.

I was looking at why the:
cs.owner.members().enter(cs);
line was added (as I assume that is the biggest offender). The reason is 
that JavacElements.getTypeElement first tries Symtab.getClass and if 
that fails to find the class, it tries JavaCompiler.resolveIdent.

Before modules, the classes entered in JavacProcessingEnvironment were 
found by Symtab.getClass; I don't think that is guaranteed in the 
modular structure. So it may fall back to resolveIdent, and for that to 
work, for classes in the unnamed package, the class must be a member of 
that package. So adding the class into the package's scope.

So the change in JavacProcessingEnvironment could be, I think, rewritten as:
if (cs.owner.kind == PCK) {
     cs.owner.members().enterIfAbsent(cs);
}

(that would also prevent an unnecessary complete.)

The change in ClassReader seems unnecessary, or am I mistaken?

What do you think?

Thanks,
     Jan

On 8.6.2018 20:15, Liam Miller-Cushon wrote:
> Hi,
>
> This patch fixes an NPE in JavacProcessingEnvironment when attempting to
> generate the class file for an anonymous class from an annotation
> processor using Filer#createClassFile.
>
> bug: https://bugs.openjdk.java.net/browse/JDK-8204630
> webrev: http://cr.openjdk.java.net/~cushon/8204630/webrev.00/
>
> Thanks,
> Liam


More information about the compiler-dev mailing list