8138729: javac -parameters should not emit parameter names for lambda expressions
authorsadayapalam
Wed, 21 Oct 2015 17:52:43 +0530
changeset 33364 542040bb5990
parent 33363 f03a03067799
child 33365 b25c5559727e
8138729: javac -parameters should not emit parameter names for lambda expressions Reviewed-by: mcimadamore
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
langtools/test/tools/javac/MethodParameters/ClassFileVisitor.java
langtools/test/tools/javac/MethodParameters/LambdaTest.java
langtools/test/tools/javac/MethodParameters/LambdaTest.out
langtools/test/tools/javac/MethodParameters/ReflectionVisitor.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Tue Oct 20 15:25:41 2015 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Wed Oct 21 17:52:43 2015 +0530
@@ -1597,6 +1597,10 @@
             }
         }
 
+        public boolean isLambdaMethod() {
+            return (flags() & LAMBDA_METHOD) == LAMBDA_METHOD;
+        }
+
         /** The implementation of this (abstract) symbol in class origin;
          *  null if none exists. Synthetic methods are not considered
          *  as possible implementations.
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Tue Oct 20 15:25:41 2015 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Wed Oct 21 17:52:43 2015 +0530
@@ -1107,8 +1107,10 @@
             endAttr(alenIdx);
             acount++;
         }
-        if (options.isSet(PARAMETERS))
-            acount += writeMethodParametersAttr(m);
+        if (options.isSet(PARAMETERS)) {
+            if (!m.isLambdaMethod()) // Per JDK-8138729, do not emit parameters table for lambda bodies.
+                acount += writeMethodParametersAttr(m);
+        }
         acount += writeMemberAttrs(m);
         acount += writeParameterAttrs(m);
         endAttrs(acountIdx, acount);
--- a/langtools/test/tools/javac/MethodParameters/ClassFileVisitor.java	Tue Oct 20 15:25:41 2015 +0530
+++ b/langtools/test/tools/javac/MethodParameters/ClassFileVisitor.java	Wed Oct 21 17:52:43 2015 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -147,7 +147,6 @@
         public int mAttrs;
         public int mNumParams;
         public boolean mSynthetic;
-        public boolean mIsLambda;
         public boolean mIsConstructor;
         public boolean mIsClinit;
         public boolean mIsBridge;
@@ -166,7 +165,6 @@
             mIsClinit = mName.equals("<clinit>");
             prefix = cname + "." + mName + "() - ";
             mIsBridge = method.access_flags.is(AccessFlags.ACC_BRIDGE);
-            mIsLambda = mSynthetic && mName.startsWith("lambda$");
 
             if (mIsClinit) {
                 sb = new StringBuilder(); // Discard output
@@ -227,7 +225,7 @@
 
             // IMPL: Whether MethodParameters attributes will be generated
             // for some synthetics is unresolved. For now, assume no.
-            if (mSynthetic && !mIsLambda) {
+            if (mSynthetic) {
                 warn(prefix + "synthetic has MethodParameter attribute");
             }
 
@@ -351,12 +349,10 @@
             } else if (isEnum && mNumParams == 1 && index == 0 && mName.equals("valueOf")) {
                 expect = "name";
                 allowMandated = true;
-            } else if (mIsBridge || mIsLambda) {
+            } else if (mIsBridge) {
                 allowSynthetic = true;
                 /*  you can't expect an special name for bridges' parameters.
-                 *  The name of the original parameters are now copied. Likewise
-                 *  for a method encoding the lambda expression, names are derived
-                 *  from source lambda's parameters and captured enclosing locals.
+                 *  The name of the original parameters are now copied.
                  */
                 expect = null;
             }
--- a/langtools/test/tools/javac/MethodParameters/LambdaTest.java	Tue Oct 20 15:25:41 2015 +0530
+++ b/langtools/test/tools/javac/MethodParameters/LambdaTest.java	Wed Oct 21 17:52:43 2015 +0530
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8006582 8037546
+ * @bug 8006582 8037546 8138729
  * @summary javac should generate method parameters correctly.
  * @modules jdk.jdeps/com.sun.tools.classfile
  * @build Tester
@@ -32,8 +32,8 @@
  */
 
 /**
- * Post https://bugs.openjdk.java.net/browse/JDK-8037546, this test verifies
- * that MethodParameters attribute for lambdas are emitted properly.
+ * Post https://bugs.openjdk.java.net/browse/JDK-8138729, this test verifies
+ * that MethodParameters attribute are NOT emitted for lambdas.
  */
 class LambdaTest {
 
--- a/langtools/test/tools/javac/MethodParameters/LambdaTest.out	Tue Oct 20 15:25:41 2015 +0530
+++ b/langtools/test/tools/javac/MethodParameters/LambdaTest.out	Wed Oct 21 17:52:43 2015 +0530
@@ -1,7 +1,7 @@
 class LambdaTest -- 
 LambdaTest.<init>()
 LambdaTest.foo(i)
-LambdaTest.lambda$static$1(x1/*synthetic*/)/*synthetic*/
-LambdaTest.lambda$null$0(final x1/*synthetic*/, x2/*synthetic*/)/*synthetic*/
+LambdaTest.lambda$static$1(arg0)/*synthetic*/
+LambdaTest.lambda$null$0(arg0, arg1)/*synthetic*/
 static interface LambdaTest$I -- inner
 LambdaTest$I.m(x)
--- a/langtools/test/tools/javac/MethodParameters/ReflectionVisitor.java	Tue Oct 20 15:25:41 2015 +0530
+++ b/langtools/test/tools/javac/MethodParameters/ReflectionVisitor.java	Wed Oct 21 17:52:43 2015 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -277,7 +277,7 @@
                     param = "final " + param;
                 }
                 sb.append(sep).append(param);
-                if (!m.isBridge() && !m.getName().startsWith("lambda$") && !expect.equals(param)) {
+                if (!m.isBridge() && !expect.equals(param)) {
                     error(prefix + "param[" + i + "]='"
                           + param + "' expected '" + expect + "'");
                     break;