RFR: JDK-8243047: javac may crash when processing exists in class initializers

Jan Lahoda jan.lahoda at oracle.com
Fri Apr 17 09:25:24 UTC 2020


Hi,

For code like:
---
public class ExitInInitializer {
     {return;}
}
---

If javac is invoked like:
$ javac -XDshould-stop.at=FLOW -XDdev ExitInInitializer.java

javac eventually crashes with:
java.lang.AssertionError
         at 
jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
         at 
jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
         at 
jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitMethodDef(Flow.java:558)

The reason is that the the (invalid) "return" in the intializer is added 
to pendingExits, but not removed as the end of the initializer, and when 
analyzing method, javac checks pendingExits are empty.

The proposed solution is to clear pendingExits at the end of 
initializers. The asserts that an error had to be reported for such 
exits is preserved, so there shouldn't be a danger of accidentally 
letting incorrect compilation pass.

Webrev:
http://cr.openjdk.java.net/~jlahoda/8243047/webrev.00/

JBS: https://bugs.openjdk.java.net/browse/JDK-8243047

How does this look?

Thanks,
     Jan


More information about the compiler-dev mailing list