JDK-8189335: NPE in Lower due to class name clash
B. Blaser
bsrbnd at gmail.com
Mon Feb 19 14:53:02 UTC 2018
On 19 February 2018 at 00:42, B. Blaser <bsrbnd at gmail.com> wrote:
> Hi,
>
> As explained in JDK-8189335, the following example crashes javac with
> a NPE in Lower:
>
> class R {
> private class R$1 {}
> void f() {
> new R$1();
> }
> }
> class R$1 {}
>
> This seems to be due to the fact that javac wrongly concludes that the
> constructor of 'R$1' needs private access and then generates an
> anonymous class 'R$1' (see Lower.accessConstructor()) which conflicts
> with the top level class using the same name.
Another simpler solution would be to create an anonymous class if the
existing one isn't anonymous... as next.
Bernard
diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
@@ -1236,7 +1236,7 @@
target.syntheticNameChar() +
"1");
ClassSymbol ctag = chk.getCompiled(topModle, flatname);
- if (ctag == null)
+ if (ctag == null || !ctag.isAnonymous())
ctag = makeEmptyClass(STATIC | SYNTHETIC, topClass).sym;
// keep a record of all tags, to verify that all are
generated as required
accessConstrTags = accessConstrTags.prepend(ctag);
More information about the compiler-dev
mailing list