-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
17.0.9
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
System:Windows 11 专业版 24H2 26100.4652
JDK(error):graalvm-ce-17.0.9
javac args:"C:\Users\AXM\.jdks\graalvm-ce-17.0.9\bin\javac.exe" .\YieldTest.java
A DESCRIPTION OF THE PROBLEM :
An anonymous inner class was used in the switch (using lambda would not cause this issue), and the method names of the anonymous inner class were used in the method implementation of the anonymous inner class. That is to say, using temporary variables from the case code block in '@ Override public void run()' will result in an error
在switch中使用了匿名内部类(使用lambda不会有此问题),并且在匿名内部类中的方法实现中使用了匿名内部类的方法名称。也就是在“ @Override public void run()”使用了case代码块里面的临时变量就会报错
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the code using Javac, please refer to the test case for the code.
使用javac编译代码,代码请看测试用例。
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
There will be no output and the compilation will be successful
不会有任何输出,并且编译成功
ACTUAL -
编译器 (17.0.9) 中出现异常错误。如果在 Bug Database (https://bugs.java.com) 中没有找到该错误,请通过 Java Bug 报告页 (https://bugreport.java.com) 建立该 Java 编译器 Bug。请在报告中附上您的程序、以下诊断信息以及传递到 Java 编译器的参数。谢谢。
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.Lower.access(Lower.java:1125)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitIdent(Lower.java:3361)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2584)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitSelect(Lower.java:4046)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2450)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitApply(Lower.java:3029)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1797)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitExec(TreeTranslator.java:256)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1584)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:167)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:3552)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1091)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:150)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2727)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2639)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:921)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2214)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:819)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitNewClass(Lower.java:2824)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1852)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2083)
at jdk.compiler/com.sun.tools.javac.comp.Lower.boxArgs(Lower.java:3072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitApply(Lower.java:2975)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1797)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitExec(TreeTranslator.java:256)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1584)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:167)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:3552)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1091)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitCase(TreeTranslator.java:211)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCase.accept(JCTree.java:1335)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translateCases(TreeTranslator.java:94)
at jdk.compiler/com.sun.tools.javac.comp.Lower.handleSwitch(Lower.java:3654)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitSwitchExpression(Lower.java:3593)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCSwitchExpression.accept(JCTree.java:1380)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2083)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitVarDef(Lower.java:3538)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1027)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:167)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:3552)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1091)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:150)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2727)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2639)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:921)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2214)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:819)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2091)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:4138)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1561)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1408)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
正在将 javac 参数打印到:D:\TempDir\YieldTest\javac.20250713_165931.args
---------- BEGIN SOURCE ----------
import java.util.List;
public class YieldTest {
public static void main(String[] args) {
List.of("a", "b", "c").forEach((k) -> {
Object value = switch ("123") {
case "123" -> {
Object temp = new Object();
AXMEntity axmEntity = new AXMEntity();
axmEntity.addListener(new Runnable() {
@Override
public void run() {
temp.hashCode();
//访问case里面的对象就报错
//Accessing objects in the case will result in an error
}
});
yield "null";
}
default -> null;
};
});
}
static class AXMEntity {
public void addListener(Runnable runnable) {
}
}
}
---------- END SOURCE ----------
System:Windows 11 专业版 24H2 26100.4652
JDK(error):graalvm-ce-17.0.9
javac args:"C:\Users\AXM\.jdks\graalvm-ce-17.0.9\bin\javac.exe" .\YieldTest.java
A DESCRIPTION OF THE PROBLEM :
An anonymous inner class was used in the switch (using lambda would not cause this issue), and the method names of the anonymous inner class were used in the method implementation of the anonymous inner class. That is to say, using temporary variables from the case code block in '@ Override public void run()' will result in an error
在switch中使用了匿名内部类(使用lambda不会有此问题),并且在匿名内部类中的方法实现中使用了匿名内部类的方法名称。也就是在“ @Override public void run()”使用了case代码块里面的临时变量就会报错
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the code using Javac, please refer to the test case for the code.
使用javac编译代码,代码请看测试用例。
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
There will be no output and the compilation will be successful
不会有任何输出,并且编译成功
ACTUAL -
编译器 (17.0.9) 中出现异常错误。如果在 Bug Database (https://bugs.java.com) 中没有找到该错误,请通过 Java Bug 报告页 (https://bugreport.java.com) 建立该 Java 编译器 Bug。请在报告中附上您的程序、以下诊断信息以及传递到 Java 编译器的参数。谢谢。
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.Lower.access(Lower.java:1125)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitIdent(Lower.java:3361)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2584)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitSelect(Lower.java:4046)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2450)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitApply(Lower.java:3029)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1797)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitExec(TreeTranslator.java:256)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1584)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:167)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:3552)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1091)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:150)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2727)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2639)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:921)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2214)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:819)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitNewClass(Lower.java:2824)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1852)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2083)
at jdk.compiler/com.sun.tools.javac.comp.Lower.boxArgs(Lower.java:3072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitApply(Lower.java:2975)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1797)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitExec(TreeTranslator.java:256)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1584)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:167)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:3552)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1091)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitCase(TreeTranslator.java:211)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCase.accept(JCTree.java:1335)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translateCases(TreeTranslator.java:94)
at jdk.compiler/com.sun.tools.javac.comp.Lower.handleSwitch(Lower.java:3654)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitSwitchExpression(Lower.java:3593)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCSwitchExpression.accept(JCTree.java:1380)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2083)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitVarDef(Lower.java:3538)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1027)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:167)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:3552)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1091)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:150)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2727)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2639)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:921)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2214)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:819)
at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2072)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translate(Lower.java:2091)
at jdk.compiler/com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:4138)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1561)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1408)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
正在将 javac 参数打印到:D:\TempDir\YieldTest\javac.20250713_165931.args
---------- BEGIN SOURCE ----------
import java.util.List;
public class YieldTest {
public static void main(String[] args) {
List.of("a", "b", "c").forEach((k) -> {
Object value = switch ("123") {
case "123" -> {
Object temp = new Object();
AXMEntity axmEntity = new AXMEntity();
axmEntity.addListener(new Runnable() {
@Override
public void run() {
temp.hashCode();
//访问case里面的对象就报错
//Accessing objects in the case will result in an error
}
});
yield "null";
}
default -> null;
};
});
}
static class AXMEntity {
public void addListener(Runnable runnable) {
}
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-8312229 Crash involving yield, switch and anonymous classes
-
- Resolved
-