8015648: Duplicate variable in lambda causes javac crash
Summary: Missing flag in synthetic lambda blog is causing duplicates symbol to go undetected
Reviewed-by: jjg, vromero
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Jun 06 15:35:05 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Jun 06 15:37:23 2013 +0100
@@ -2609,7 +2609,7 @@
//field initializer
lambdaEnv = env.dup(that, env.info.dup(env.info.scope.dupUnshared()));
lambdaEnv.info.scope.owner =
- new MethodSymbol(0, names.empty, null,
+ new MethodSymbol((owner.flags() & STATIC) | BLOCK, names.empty, null,
env.info.scope.owner);
} else {
lambdaEnv = env.dup(that, env.info.dup(env.info.scope.dup()));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/LambdaScope05.java Thu Jun 06 15:37:23 2013 +0100
@@ -0,0 +1,31 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8015648
+ * @summary Duplicate variable in lambda causes javac crash
+ * @compile/fail/ref=LambdaScope05.out -XDrawDiagnostics LambdaScope05.java
+ */
+
+class LambdaScope05 {
+ interface VoidFun1 {
+ void m(int i);
+ }
+
+ static Runnable r1 = () -> { VoidFun1 p = p -> { }; };
+ Runnable r2 = () -> { VoidFun1 p = p -> { }; };
+
+ static {
+ Runnable r = () -> { VoidFun1 p = p -> { }; };
+ }
+
+ {
+ Runnable r = () -> { VoidFun1 p = p -> { }; };
+ }
+
+ static void m_static() {
+ Runnable r = () -> { VoidFun1 p = p -> { }; };
+ }
+
+ void m() {
+ Runnable r = () -> { VoidFun1 p = p -> { }; };
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/LambdaScope05.out Thu Jun 06 15:37:23 2013 +0100
@@ -0,0 +1,7 @@
+LambdaScope05.java:13:47: compiler.err.already.defined.in.clinit: kindname.variable, p, kindname.static.init, kindname.class, LambdaScope05
+LambdaScope05.java:14:40: compiler.err.already.defined.in.clinit: kindname.variable, p, kindname.instance.init, kindname.class, LambdaScope05
+LambdaScope05.java:17:43: compiler.err.already.defined.in.clinit: kindname.variable, p, kindname.static.init, kindname.class, LambdaScope05
+LambdaScope05.java:21:43: compiler.err.already.defined.in.clinit: kindname.variable, p, kindname.instance.init, kindname.class, LambdaScope05
+LambdaScope05.java:25:43: compiler.err.already.defined: kindname.variable, p, kindname.method, m_static()
+LambdaScope05.java:29:43: compiler.err.already.defined: kindname.variable, p, kindname.method, m()
+6 errors