RFR: JDK-8242802: javac crashes when checking equals and hashCode in unresolvable anonymous class
Jan Lahoda
jan.lahoda at oracle.com
Wed Apr 15 18:43:25 UTC 2020
Hi,
javac may crash with an exception when running with -Xlint:options
processing code like this:
---
public class InvalidAnonymous {
private void t() {
new Undefined() {};
}
}
---
---
$ javac -XDdev -Xlint:overrides InvalidAnonymous.java
InvalidAnonymous.java:3: error: cannot find symbol
new Undefined() {};
^
symbol: class Undefined
location: class InvalidAnonymous
1 error
An exception has occurred in the compiler (15-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, the
following diagnostic, and the parameters passed to the Java compiler in
your report. Thank you.
java.lang.NullPointerException
at
jdk.compiler/com.sun.tools.javac.comp.Check.checkClassOverrideEqualsAndHash(Check.java:2148)
at
jdk.compiler/com.sun.tools.javac.comp.Check.checkClassOverrideEqualsAndHashIfNeeded(Check.java:2138)
---
This is because Types.implementation may return null if there is no
method implementing the given input method (Object.equals in this case -
and due to the "Undefined", the anonymous does not have Object as a
supertype, and hence does not have any implementation of equals).
The proposed fix is to add a null check on the result of
Types.implementation.
Webrev: http://cr.openjdk.java.net/~jlahoda/8242802/webrev.00/
JBS: https://bugs.openjdk.java.net/browse/JDK-8242802
How does this look?
Thanks,
Jan
More information about the compiler-dev
mailing list