ADDITIONAL SYSTEM INFORMATION :
java -version reports
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.17.10.1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
javac -version reports
javac 1.8.0_171
uname -v prints
#51-Ubuntu SMP Tue Jun 12 12:36:29 UTC 2018
(I'm running PopOS, a Ubuntu release provided by System 76).
A DESCRIPTION OF THE PROBLEM :
The java compiler crashed, printing a stacktrace, when there was a syntax error (a break statement not enclosed in a switch statement or loop) inside an anonymous class that was created inside a lambda expression.
I was able to create a 15 line program that reproduces the problem - short enough to be useful for debugging or for QA testing.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the command
javac CompilerBug.java
The contents of the file CompilerBug.java are included with this report.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The compiler should report that there is a syntax error on line 9 (a misplaced 'break' statement).
ACTUAL -
An exception has occurred in the compiler (1.8.0_171). 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.AssertionError
at com.sun.tools.javac.util.Assert.error(Assert.java:126)
at com.sun.tools.javac.util.Assert.check(Assert.java:45)
at com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitMethodDef(Flow.java:520)
at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:404)
at com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitClassDef(Flow.java:490)
at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:404)
at com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitNewClass(Flow.java:717)
at com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1516)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:404)
at com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitVarDef(Flow.java:532)
at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:852)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:404)
at com.sun.tools.javac.comp.Flow$AliveAnalyzer.scanStat(Flow.java:448)
at com.sun.tools.javac.comp.Flow$AliveAnalyzer.scanStats(Flow.java:456)
at com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitBlock(Flow.java:540)
at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:404)
at com.sun.tools.javac.comp.Flow$AliveAnalyzer.scanStat(Flow.java:448)
at com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitLambda(Flow.java:733)
at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:404)
at com.sun.tools.javac.comp.Flow$AliveAnalyzer.analyzeTree(Flow.java:761)
at com.sun.tools.javac.comp.Flow.analyzeLambda(Flow.java:227)
at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2410)
at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
at com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:387)
at com.sun.tools.javac.comp.DeferredAttr$2.complete(DeferredAttr.java:280)
at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:246)
at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:233)
at com.sun.tools.javac.comp.Resolve$MethodResultInfo.check(Resolve.java:1008)
at com.sun.tools.javac.comp.Resolve$4.checkArg(Resolve.java:835)
at com.sun.tools.javac.comp.Resolve$AbstractMethodCheck.argumentsAcceptable(Resolve.java:735)
at com.sun.tools.javac.comp.Resolve$4.argumentsAcceptable(Resolve.java:844)
at com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:579)
at com.sun.tools.javac.comp.Resolve.selectBest(Resolve.java:1446)
at com.sun.tools.javac.comp.Resolve.findMethodInScope(Resolve.java:1633)
at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1704)
at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1677)
at com.sun.tools.javac.comp.Resolve$9.doLookup(Resolve.java:2436)
at com.sun.tools.javac.comp.Resolve$BasicLookupHelper.lookup(Resolve.java:3097)
at com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3348)
at com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2433)
at com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2427)
at com.sun.tools.javac.comp.Attr.selectSym(Attr.java:3396)
at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3278)
at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1825)
at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:625)
at com.sun.tools.javac.comp.Attr.visitExec(Attr.java:1593)
at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1296)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:661)
at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1124)
at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1013)
at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4364)
at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4272)
at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4201)
at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4176)
at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1248)
at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
at com.sun.tools.javac.main.Main.compile(Main.java:523)
at com.sun.tools.javac.main.Main.compile(Main.java:381)
at com.sun.tools.javac.main.Main.compile(Main.java:370)
at com.sun.tools.javac.main.Main.compile(Main.java:361)
at com.sun.tools.javac.Main.compile(Main.java:56)
at com.sun.tools.javac.Main.main(Main.java:42)
---------- BEGIN SOURCE ----------
import javax.swing.SwingUtilities;
import javax.swing.Action;
import javax.swing.AbstractAction;
public class CompilerBug {
public static void example () {
SwingUtilities.invokeLater(() -> {
Action saveAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
break;
}
};
return;
});
}
}
---------- END SOURCE ----------
FREQUENCY : often