8138729: javac -parameters should not emit parameter names for lambda expressions

Reviewed-by: mcimadamore
This commit is contained in:
Srikanth Adayapalam 2015-10-21 17:52:43 +05:30
parent 08b811e8d6
commit 32cea7c65b
6 changed files with 19 additions and 17 deletions

View File

@ -1597,6 +1597,10 @@ public abstract class Symbol extends AnnoConstruct implements Element {
}
}
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.

View File

@ -1107,8 +1107,10 @@ public class ClassWriter extends ClassFile {
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);

View File

@ -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 @@ class ClassFileVisitor extends Tester.Visitor {
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 @@ class ClassFileVisitor extends Tester.Visitor {
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 @@ class ClassFileVisitor extends Tester.Visitor {
// 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 @@ class ClassFileVisitor extends Tester.Visitor {
} 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;
}

View File

@ -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 {

View File

@ -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)

View File

@ -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 @@ public class ReflectionVisitor extends Tester.Visitor {
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;