--- old/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java 2020-03-30 11:59:58.000000000 -0700 +++ new/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java 2020-03-30 11:59:58.000000000 -0700 @@ -36,7 +36,6 @@ import com.sun.tools.javac.tree.TreeMaker; import com.sun.tools.javac.tree.TreeTranslator; import com.sun.tools.javac.code.Attribute; -import com.sun.tools.javac.code.Scope.WriteableScope; import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.DynamicMethodSymbol; @@ -127,6 +126,9 @@ /** deduplicate lambda implementation methods */ private final boolean deduplicateLambdas; + /** lambda proxy is a dynamic nestmate */ + private final boolean nestmateLambdas; + /** Flag for alternate metafactories indicating the lambda object is intended to be serializable */ public static final int FLAG_SERIALIZABLE = 1 << 0; @@ -168,6 +170,7 @@ || options.isSet(Option.G_CUSTOM, "vars"); verboseDeduplication = options.isSet("debug.dumpLambdaToMethodDeduplication"); deduplicateLambdas = options.getBoolean("deduplicateLambdas", true); + nestmateLambdas = Target.instance(context).runtimeUseNestAccess(); } // @@ -2253,6 +2256,20 @@ return tree.ownerAccessible; } + /** + * This method should be called only when target release <= 14 + * where LambdaMetaFactory does not spin nestmate classes. + * + * This method should be removed when --release 14 is not supported. + */ + boolean isPrivateInOtherClass() { + assert !nestmateLambdas; + return (tree.sym.flags() & PRIVATE) != 0 && + !types.isSameType( + types.erasure(tree.sym.enclClass().asType()), + types.erasure(owner.enclClass().asType())); + } + boolean isProtectedInSuperClassOfEnclosingClassInOtherPackage() { return ((tree.sym.flags() & PROTECTED) != 0 && tree.sym.packge() != owner.packge()); @@ -2293,6 +2310,7 @@ isSuper || needsVarArgsConversion() || isArrayOp() || + (!nestmateLambdas && isPrivateInOtherClass()) || isProtectedInSuperClassOfEnclosingClassInOtherPackage() || !receiverAccessible() || (tree.getMode() == ReferenceMode.NEW &&