RFR: JDK-8193561: Cyclic hierarchy causes a NullPointerException when setting DEFAULT flag
Jan Lahoda
jan.lahoda at oracle.com
Fri Sep 14 11:33:25 UTC 2018
Hi,
Consider code like:
---
package p;
interface T8193561 extends p.T8193561.I {
interface I extends T8193561 {
default boolean m() {
return false;
}
}
default boolean m() {
return false;
}
}
---
There is apparently a cycle between the interfaces, and an error will be
reported correctly for it, but then it will crash in MemberEnter:
---
$ javac -XDdev T8193561.java
T8193561.java:9: error: cyclic inheritance involving T8193561
interface T8193561 extends p.T8193561.I {
^
1 error
An exception has occurred in the compiler (12-internal). Please file a
bug against the Java compiler via the Java bug reporting page
(http://bugreport.java.com) after checking the Bug Database
(http://bugs.java.com) for duplicates. Include your program and the
following diagnostic in your report. Thank you.
java.lang.NullPointerException
at
jdk.compiler/com.sun.tools.javac.comp.MemberEnter.visitMethodDef(MemberEnter.java:186)
[snip]
---
(Note the -XDdev - as there is an error already reported, the exception
would normally be hidden, but the crash is still observable in certain
cases, e.g. in tests.)
The offending line is:
m.enclClass().flags_field |= DEFAULT;
The issue here, IMO, is that when the cycle is detected, the
class/interface is marked as erroneous, and m.enclClass() won't return
erroneous owner (will return null instead). Seems that using "m.owner"
instead of "m.enclClass()" should be sufficient at this place?
Proposed patch: http://cr.openjdk.java.net/~jlahoda/8193561/webrev.00/
Bug: https://bugs.openjdk.java.net/browse/JDK-8193561
How does this look?
Thanks,
Jan
More information about the compiler-dev
mailing list