Certain code triggers an assertion error in the 'this' escape analysis.
Example:
$ cat Test.java
import java.util.function.Supplier;
public class Test {
public Test() {
System.out.println((Supplier<Object>)() -> this);
}
}
$ javac -Xlint:this-escape Test.java
An exception has occurred in the compiler (22-internal). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://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.AssertionError
at jdk.compiler.interim/com.sun.tools.javac.util.Assert.error(Assert.java:155)
at jdk.compiler.interim/com.sun.tools.javac.util.Assert.check(Assert.java:46)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.checkInvariants(ThisEscapeAnalyzer.java:1209)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.visitScoped(ThisEscapeAnalyzer.java:1103)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.lambda$visitLambda$24(ThisEscapeAnalyzer.java:732)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.visitDeferred(ThisEscapeAnalyzer.java:1073)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.visitLambda(ThisEscapeAnalyzer.java:732)
at jdk.compiler.interim/com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1993)
at jdk.compiler.interim/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.scan(ThisEscapeAnalyzer.java:462)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.visitTypeCast(ThisEscapeAnalyzer.java:949)
at jdk.compiler.interim/com.sun.tools.javac.tree.JCTree$JCTypeCast.accept(JCTree.java:2204)
at jdk.compiler.interim/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.scan(ThisEscapeAnalyzer.java:462)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.invokeUnknown(ThisEscapeAnalyzer.java:623)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.invoke(ThisEscapeAnalyzer.java:552)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.visitApply(ThisEscapeAnalyzer.java:530)
at jdk.compiler.interim/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1816)
at jdk.compiler.interim/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.scan(ThisEscapeAnalyzer.java:462)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.visitExec(ThisEscapeAnalyzer.java:915)
at jdk.compiler.interim/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1603)
at jdk.compiler.interim/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.scan(ThisEscapeAnalyzer.java:462)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.analyzeStatements(ThisEscapeAnalyzer.java:419)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.lambda$analyzeTree$6(ThisEscapeAnalyzer.java:358)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.visitScoped(ThisEscapeAnalyzer.java:1102)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.visitTopLevel(ThisEscapeAnalyzer.java:1052)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.lambda$analyzeTree$7(ThisEscapeAnalyzer.java:357)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1939)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at jdk.compiler.interim/com.sun.tools.javac.comp.ThisEscapeAnalyzer.analyzeTree(ThisEscapeAnalyzer.java:356)
at jdk.compiler.interim/com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:233)
at jdk.compiler.interim/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1426)
at jdk.compiler.interim/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1400)
at jdk.compiler.interim/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:976)
at jdk.compiler.interim/com.sun.tools.javac.main.Main.compile(Main.java:319)
at jdk.compiler.interim/com.sun.tools.javac.main.Main.compile(Main.java:178)
at jdk.compiler.interim/com.sun.tools.javac.Main.compile(Main.java:66)
at jdk.compiler.interim/com.sun.tools.javac.Main.main(Main.java:52)
$ java -version
openjdk version "21" 2023-09-19
OpenJDK Runtime Environment Homebrew (build 21)
OpenJDK 64-Bit Server VM Homebrew (build 21, mixed mode, sharing)