8026721: Enhance Lambda serialization
authorvromero
Wed, 02 Mar 2016 18:25:01 -0500
changeset 41629 9d203cde7d84
parent 41628 664e7664343d
child 41630 9cc5bcc88057
8026721: Enhance Lambda serialization Reviewed-by: jjg, briangoetz
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/AttrContext.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties
langtools/test/tools/javac/T8029102/WarnSerializableElementTest.java
langtools/test/tools/javac/T8029102/WarnSerializableElementTest.out
langtools/test/tools/javac/T8029102/WarnSerializableLambdaTest.java
langtools/test/tools/javac/T8029102/WarnSerializableLambdaTest.out
langtools/test/tools/javac/T8029102/WarnSerializableLambdaTestb.java
langtools/test/tools/javac/T8029102/WarnSerializableLambdaTestb.out
langtools/test/tools/javac/T8029102/WarnSerializableLambdaTestc.java
langtools/test/tools/javac/T8029102/WarnSerializableLambdaTestc.out
langtools/test/tools/javac/diags/CheckResourceKeys.java
langtools/test/tools/javac/diags/examples.not-yet.txt
langtools/test/tools/javac/diags/examples/WarnSerializableLambda.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Oct 18 16:00:32 2016 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Mar 02 18:25:01 2016 -0500
@@ -2398,6 +2398,7 @@
         try {
             if (needsRecovery && isSerializable(pt())) {
                 localEnv.info.isSerializable = true;
+                localEnv.info.isLambda = true;
             }
             List<Type> explicitParamTypes = null;
             if (that.paramKind == JCLambda.ParameterKind.EXPLICIT) {
@@ -2969,7 +2970,7 @@
                 }
 
                 if (isTargetSerializable) {
-                    chk.checkElemAccessFromSerializableLambda(that);
+                    chk.checkAccessFromSerializableElement(that, true);
                 }
             }
 
@@ -3364,7 +3365,7 @@
         }
 
         if (env.info.isSerializable) {
-            chk.checkElemAccessFromSerializableLambda(tree);
+            chk.checkAccessFromSerializableElement(tree, env.info.isLambda);
         }
 
         result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo);
@@ -3507,7 +3508,7 @@
         }
 
         if (env.info.isSerializable) {
-            chk.checkElemAccessFromSerializableLambda(tree);
+            chk.checkAccessFromSerializableElement(tree, env.info.isLambda);
         }
 
         env.info.selectSuper = selectSuperPrev;
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/AttrContext.java	Tue Oct 18 16:00:32 2016 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/AttrContext.java	Wed Mar 02 18:25:01 2016 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2016, 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
@@ -56,10 +56,15 @@
      */
     boolean selectSuper = false;
 
-    /** Is the current target of lambda expression or method reference serializable?
+    /** Is the current target of lambda expression or method reference serializable or is this a
+     *  serializable class?
      */
     boolean isSerializable = false;
 
+    /** Is this a lambda environment?
+     */
+    boolean isLambda = false;
+
     /** Is this a speculative attribution environment?
      */
     boolean isSpeculative = false;
@@ -117,6 +122,7 @@
         info.returnResult = returnResult;
         info.defaultSuperCallSite = defaultSuperCallSite;
         info.isSerializable = isSerializable;
+        info.isLambda = isLambda;
         info.isSpeculative = isSpeculative;
         info.isAnonymousDiamond = isAnonymousDiamond;
         info.isNewClass = isNewClass;
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Tue Oct 18 16:00:32 2016 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Wed Mar 02 18:25:01 2016 -0500
@@ -87,7 +87,7 @@
     private final JavaFileManager fileManager;
     private final Source source;
     private final Profile profile;
-    private final boolean warnOnAccessToSensitiveMembers;
+    private final boolean warnOnAnyAccessToMembers;
 
     // The set of lint options currently in effect. It is initialized
     // from the context, and then is set/reset as needed by Attr as it
@@ -131,7 +131,7 @@
         allowStrictMethodClashCheck = source.allowStrictMethodClashCheck();
         allowPrivateSafeVarargs = source.allowPrivateSafeVarargs();
         allowDiamondWithAnonymousClassCreation = source.allowDiamondWithAnonymousClassCreation();
-        warnOnAccessToSensitiveMembers = options.isSet("warnOnAccessToSensitiveMembers");
+        warnOnAnyAccessToMembers = options.isSet("warnOnAccessToMembers");
 
         Target target = Target.instance(context);
         syntheticNameChar = target.syntheticNameChar();
@@ -2605,8 +2605,11 @@
         }
     }
 
-    void checkElemAccessFromSerializableLambda(final JCTree tree) {
-        if (warnOnAccessToSensitiveMembers) {
+    void checkAccessFromSerializableElement(final JCTree tree, boolean isLambda) {
+        if (warnOnAnyAccessToMembers ||
+            (lint.isEnabled(LintCategory.SERIAL) &&
+            !lint.isSuppressed(LintCategory.SERIAL) &&
+            isLambda)) {
             Symbol sym = TreeInfo.symbol(tree);
             if (!sym.kind.matches(KindSelector.VAL_MTH)) {
                 return;
@@ -2622,9 +2625,16 @@
             }
 
             if (!types.isSubtype(sym.owner.type, syms.serializableType) &&
-                    isEffectivelyNonPublic(sym)) {
-                log.warning(tree.pos(),
-                        "access.to.sensitive.member.from.serializable.element", sym);
+                isEffectivelyNonPublic(sym)) {
+                if (isLambda) {
+                    if (belongsToRestrictedPackage(sym)) {
+                        log.warning(LintCategory.SERIAL, tree.pos(),
+                            "access.to.member.from.serializable.lambda", sym);
+                    }
+                } else {
+                    log.warning(tree.pos(),
+                        "access.to.member.from.serializable.element", sym);
+                }
             }
         }
     }
@@ -2643,6 +2653,14 @@
         return false;
     }
 
+    private boolean belongsToRestrictedPackage(Symbol sym) {
+        String fullName = sym.packge().fullname.toString();
+        return fullName.startsWith("java.") ||
+                fullName.startsWith("javax.") ||
+                fullName.startsWith("sun.") ||
+                fullName.contains(".internal.");
+    }
+
     /** Report a conflict between a user symbol and a synthetic symbol.
      */
     private void syntheticError(DiagnosticPosition pos, Symbol sym) {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Oct 18 16:00:32 2016 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Wed Mar 02 18:25:01 2016 -0500
@@ -1712,8 +1712,12 @@
     Redundant {0} annotation. {1}
 
 # 0: symbol
-compiler.warn.access.to.sensitive.member.from.serializable.element=\
-    access to sensitive member {0} from serializable element can be publicly accessible to untrusted code
+compiler.warn.access.to.member.from.serializable.element=\
+    access to member {0} from serializable element can be publicly accessible to untrusted code
+
+# 0: symbol
+compiler.warn.access.to.member.from.serializable.lambda=\
+    access to member {0} from serializable lambda can be publicly accessible to untrusted code
 
 #####
 
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties	Tue Oct 18 16:00:32 2016 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties	Wed Mar 02 18:25:01 2016 -0500
@@ -220,7 +220,8 @@
     Warn about use of raw types.
 
 javac.opt.Xlint.desc.serial=\
-    Warn about Serializable classes that do not provide a serial version ID.
+    Warn about Serializable classes that do not provide a serial version ID. \n\
+\                             Also warn about access to non-public members from a serializable element.
 
 javac.opt.Xlint.desc.static=\
     Warn about accessing a static member using an instance.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8029102/WarnSerializableElementTest.java	Wed Mar 02 18:25:01 2016 -0500
@@ -0,0 +1,241 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8029102
+ * @summary Enhance compiler warnings for Lambda
+ *     Checks that the warning for accessing non public members of a class is
+ *     fired correctly.
+ * @compile/fail/ref=WarnSerializableElementTest.out -XDrawDiagnostics -Werror -XDwarnOnAccessToMembers WarnSerializableElementTest.java
+ */
+
+import java.io.Serializable;
+
+public class WarnSerializableElementTest {
+
+    void warnLambda() throws Exception {
+        SAM t3 = (SAM & Serializable)WarnSerializableElementTest::packageClassMethod;
+        SAM t4 = (SAM & Serializable)WarnSerializableElementTest::protectedClassMethod;
+        SAM t5 = (SAM & Serializable)WarnSerializableElementTest::privateClassMethod;
+
+        WarnSerializableElementTest test = new WarnSerializableElementTest();
+        SAM t6 = (SAM & Serializable)test::packageInstanceMethod;
+        SAM t7 = (SAM & Serializable)test::protectedInstanceMethod;
+        SAM t8 = (SAM & Serializable)test::privateInstanceMethod;
+
+        SAM t9 = (SAM & Serializable) c -> {
+
+            WarnSerializableElementTest.staticPackageField = "";
+            WarnSerializableElementTest.staticProtectedField = "";
+            WarnSerializableElementTest.staticPrivateField = "";
+
+            packageField = "";
+            protectedField = "";
+            privateField = "";
+
+            WarnSerializableElementTest.packageClassMethod(null);
+            WarnSerializableElementTest.protectedClassMethod(null);
+            WarnSerializableElementTest.privateClassMethod(null);
+
+            packageInstanceMethod(null);
+            protectedInstanceMethod(null);
+            privateInstanceMethod(null);
+
+            PrivateClass.effectivelyNonPublicStaticField = "";
+            PrivateClass.effectivelyNonPublicClassMethod();
+
+            PrivateClass p = new PrivateClass();
+            p.effectivelyNonPublicInstanceField = "";
+            p.effectivelyNonPublicInstanceMethod();
+
+            return null;
+        };
+    }
+
+    private void warnAnoInnerClass() throws Exception {
+        new SerializableDesc() {
+            public void m(Object param) throws Exception {
+                WarnSerializableElementTest.staticPackageField = "";
+                WarnSerializableElementTest.staticProtectedField = "";
+                WarnSerializableElementTest.staticPrivateField = "";
+
+                packageField = "";
+                protectedField = "";
+                privateField = "";
+
+                WarnSerializableElementTest.packageClassMethod(null);
+                WarnSerializableElementTest.protectedClassMethod(null);
+                WarnSerializableElementTest.privateClassMethod(null);
+
+                packageInstanceMethod(null);
+                protectedInstanceMethod(null);
+                privateInstanceMethod(null);
+
+                PrivateClass.effectivelyNonPublicStaticField = "";
+                PrivateClass.effectivelyNonPublicClassMethod();
+
+                PrivateClass p = new PrivateClass();
+                p.effectivelyNonPublicInstanceField = "";
+                p.effectivelyNonPublicInstanceMethod();
+            }
+        };
+    }
+
+    void dontWarnLambda() throws Exception {
+        SAM t1 = (SAM & Serializable)WarnSerializableElementTest::publicClassMethod;
+
+        WarnSerializableElementTest test = new WarnSerializableElementTest();
+        SAM t2 = (SAM & Serializable)test::publicInstanceMethod;
+
+        int[] buffer = {0};
+
+        SAM t3 = (SAM & Serializable) param -> {
+            Object localVar;
+            localVar = null;
+            param = null;
+
+            WarnSerializableElementTest.staticPublicField = "";
+            publicField = "";
+            WarnSerializableElementTest.publicClassMethod(null);
+            publicInstanceMethod(null);
+
+            PublicClass.effectivelyPublicStaticField = "";
+            PublicClass.effectivelyPublicClassMethod();
+
+            PublicClass p = new PublicClass();
+            p.effectivelyPublicInstanceField = "";
+            p.effectivelyPublicInstanceMethod();
+
+            int l = buffer.length;
+
+            return null;
+        };
+    }
+
+    private void dontWarnAnoInnerClass() throws Exception {
+        final int[] buffer = {0};
+        new SerializableDesc() {
+            public void m(Object param) throws Exception {
+                Object localVar;
+                localVar = null;
+                param = null;
+
+                WarnSerializableElementTest.staticPublicField = "";
+                publicField = "";
+                WarnSerializableElementTest.publicClassMethod(null);
+                publicInstanceMethod(null);
+
+                PublicClass.effectivelyPublicStaticField = "";
+                PublicClass.effectivelyPublicClassMethod();
+
+                PublicClass p = new PublicClass();
+                p.effectivelyPublicInstanceField = "";
+                p.effectivelyPublicInstanceMethod();
+
+                int l = buffer.length;
+            }
+        };
+    }
+
+    enum WarnEnum {
+        A {
+            public void m() throws Exception {
+                WarnSerializableElementTest.staticPackageField = "";
+                WarnSerializableElementTest.staticProtectedField = "";
+                WarnSerializableElementTest.staticPrivateField = "";
+
+                WarnSerializableElementTest test =
+                        new WarnSerializableElementTest();
+
+                test.packageField = "";
+                test.protectedField = "";
+                test.privateField = "";
+
+                WarnSerializableElementTest.packageClassMethod(null);
+                WarnSerializableElementTest.protectedClassMethod(null);
+                WarnSerializableElementTest.privateClassMethod(null);
+
+                test.packageInstanceMethod(null);
+                test.protectedInstanceMethod(null);
+                test.privateInstanceMethod(null);
+
+                PrivateClass.effectivelyNonPublicStaticField = "";
+                PrivateClass.effectivelyNonPublicClassMethod();
+
+                PrivateClass p = new PrivateClass();
+                p.effectivelyNonPublicInstanceField = "";
+                p.effectivelyNonPublicInstanceMethod();
+            }
+        };
+
+        public void m() throws Exception {}
+    }
+
+    static String staticPackageField;
+    static private String staticPrivateField;
+    static protected String staticProtectedField;
+    static public String staticPublicField;
+
+    String packageField;
+    private String privateField;
+    protected String protectedField;
+    public String publicField;
+
+    static Object packageClassMethod(String s) {
+        return null;
+    }
+
+    static private Object privateClassMethod(String s) {
+        return null;
+    }
+
+    static protected Object protectedClassMethod(String s) {
+        return null;
+    }
+
+    static public Object publicClassMethod(String s) {
+        return null;
+    }
+
+    Object packageInstanceMethod(String s) {
+        return null;
+    }
+
+    protected Object protectedInstanceMethod(String s) {
+        return null;
+    }
+
+    private Object privateInstanceMethod(String s) {
+        return null;
+    }
+
+    public Object publicInstanceMethod(String s) {
+        return null;
+    }
+
+    interface SAM {
+        Object apply(String s) throws Exception;
+    }
+
+    interface SAM2 {
+        Object apply(String arg1, String arg2);
+    }
+
+    class SerializableDesc implements Serializable {
+        public void m(Object param) throws Exception {}
+    }
+
+    static private class PrivateClass {
+        static public String effectivelyNonPublicStaticField;
+        public String effectivelyNonPublicInstanceField;
+
+        static public void effectivelyNonPublicClassMethod() {}
+        public void effectivelyNonPublicInstanceMethod() {}
+    }
+
+    static public class PublicClass {
+        static public String effectivelyPublicStaticField;
+        public String effectivelyPublicInstanceField;
+
+        static public void effectivelyPublicClassMethod() {}
+        public void effectivelyPublicInstanceMethod() {}
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8029102/WarnSerializableElementTest.out	Wed Mar 02 18:25:01 2016 -0500
@@ -0,0 +1,35 @@
+WarnSerializableElementTest.java:56:44: compiler.warn.access.to.member.from.serializable.element: staticPackageField
+WarnSerializableElementTest.java:57:44: compiler.warn.access.to.member.from.serializable.element: staticProtectedField
+WarnSerializableElementTest.java:58:44: compiler.warn.access.to.member.from.serializable.element: staticPrivateField
+WarnSerializableElementTest.java:60:17: compiler.warn.access.to.member.from.serializable.element: packageField
+WarnSerializableElementTest.java:61:17: compiler.warn.access.to.member.from.serializable.element: protectedField
+WarnSerializableElementTest.java:62:17: compiler.warn.access.to.member.from.serializable.element: privateField
+WarnSerializableElementTest.java:64:44: compiler.warn.access.to.member.from.serializable.element: packageClassMethod(java.lang.String)
+WarnSerializableElementTest.java:65:44: compiler.warn.access.to.member.from.serializable.element: protectedClassMethod(java.lang.String)
+WarnSerializableElementTest.java:66:44: compiler.warn.access.to.member.from.serializable.element: privateClassMethod(java.lang.String)
+WarnSerializableElementTest.java:68:17: compiler.warn.access.to.member.from.serializable.element: packageInstanceMethod(java.lang.String)
+WarnSerializableElementTest.java:69:17: compiler.warn.access.to.member.from.serializable.element: protectedInstanceMethod(java.lang.String)
+WarnSerializableElementTest.java:70:17: compiler.warn.access.to.member.from.serializable.element: privateInstanceMethod(java.lang.String)
+WarnSerializableElementTest.java:72:29: compiler.warn.access.to.member.from.serializable.element: effectivelyNonPublicStaticField
+WarnSerializableElementTest.java:73:29: compiler.warn.access.to.member.from.serializable.element: effectivelyNonPublicClassMethod()
+WarnSerializableElementTest.java:76:18: compiler.warn.access.to.member.from.serializable.element: effectivelyNonPublicInstanceField
+WarnSerializableElementTest.java:77:18: compiler.warn.access.to.member.from.serializable.element: effectivelyNonPublicInstanceMethod()
+WarnSerializableElementTest.java:141:44: compiler.warn.access.to.member.from.serializable.element: staticPackageField
+WarnSerializableElementTest.java:142:44: compiler.warn.access.to.member.from.serializable.element: staticProtectedField
+WarnSerializableElementTest.java:143:44: compiler.warn.access.to.member.from.serializable.element: staticPrivateField
+WarnSerializableElementTest.java:148:21: compiler.warn.access.to.member.from.serializable.element: packageField
+WarnSerializableElementTest.java:149:21: compiler.warn.access.to.member.from.serializable.element: protectedField
+WarnSerializableElementTest.java:150:21: compiler.warn.access.to.member.from.serializable.element: privateField
+WarnSerializableElementTest.java:152:44: compiler.warn.access.to.member.from.serializable.element: packageClassMethod(java.lang.String)
+WarnSerializableElementTest.java:153:44: compiler.warn.access.to.member.from.serializable.element: protectedClassMethod(java.lang.String)
+WarnSerializableElementTest.java:154:44: compiler.warn.access.to.member.from.serializable.element: privateClassMethod(java.lang.String)
+WarnSerializableElementTest.java:156:21: compiler.warn.access.to.member.from.serializable.element: packageInstanceMethod(java.lang.String)
+WarnSerializableElementTest.java:157:21: compiler.warn.access.to.member.from.serializable.element: protectedInstanceMethod(java.lang.String)
+WarnSerializableElementTest.java:158:21: compiler.warn.access.to.member.from.serializable.element: privateInstanceMethod(java.lang.String)
+WarnSerializableElementTest.java:160:29: compiler.warn.access.to.member.from.serializable.element: effectivelyNonPublicStaticField
+WarnSerializableElementTest.java:161:29: compiler.warn.access.to.member.from.serializable.element: effectivelyNonPublicClassMethod()
+WarnSerializableElementTest.java:164:18: compiler.warn.access.to.member.from.serializable.element: effectivelyNonPublicInstanceField
+WarnSerializableElementTest.java:165:18: compiler.warn.access.to.member.from.serializable.element: effectivelyNonPublicInstanceMethod()
+- compiler.err.warnings.and.werror
+1 error
+32 warnings
--- a/langtools/test/tools/javac/T8029102/WarnSerializableLambdaTest.java	Tue Oct 18 16:00:32 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,241 +0,0 @@
-/*
- * @test /nodynamiccopyright/
- * @bug 8029102
- * @summary Enhance compiler warnings for Lambda
- *     Checks that the warning for accessing non public members of a class is
- *     fired correctly.
- * @compile/fail/ref=WarnSerializableLambdaTest.out -XDrawDiagnostics -Werror -XDwarnOnAccessToSensitiveMembers WarnSerializableLambdaTest.java
- */
-
-import java.io.Serializable;
-
-public class WarnSerializableLambdaTest {
-
-    void warnLambda() throws Exception {
-        SAM t3 = (SAM & Serializable)WarnSerializableLambdaTest::packageClassMethod;
-        SAM t4 = (SAM & Serializable)WarnSerializableLambdaTest::protectedClassMethod;
-        SAM t5 = (SAM & Serializable)WarnSerializableLambdaTest::privateClassMethod;
-
-        WarnSerializableLambdaTest test = new WarnSerializableLambdaTest();
-        SAM t6 = (SAM & Serializable)test::packageInstanceMethod;
-        SAM t7 = (SAM & Serializable)test::protectedInstanceMethod;
-        SAM t8 = (SAM & Serializable)test::privateInstanceMethod;
-
-        SAM t9 = (SAM & Serializable) c -> {
-
-            WarnSerializableLambdaTest.staticPackageField = "";
-            WarnSerializableLambdaTest.staticProtectedField = "";
-            WarnSerializableLambdaTest.staticPrivateField = "";
-
-            packageField = "";
-            protectedField = "";
-            privateField = "";
-
-            WarnSerializableLambdaTest.packageClassMethod(null);
-            WarnSerializableLambdaTest.protectedClassMethod(null);
-            WarnSerializableLambdaTest.privateClassMethod(null);
-
-            packageInstanceMethod(null);
-            protectedInstanceMethod(null);
-            privateInstanceMethod(null);
-
-            PrivateClass.effectivelyNonPublicStaticField = "";
-            PrivateClass.effectivelyNonPublicClassMethod();
-
-            PrivateClass p = new PrivateClass();
-            p.effectivelyNonPublicInstanceField = "";
-            p.effectivelyNonPublicInstanceMethod();
-
-            return null;
-        };
-    }
-
-    private void warnAnoInnerClass() throws Exception {
-        new SerializableDesc() {
-            public void m(Object param) throws Exception {
-                WarnSerializableLambdaTest.staticPackageField = "";
-                WarnSerializableLambdaTest.staticProtectedField = "";
-                WarnSerializableLambdaTest.staticPrivateField = "";
-
-                packageField = "";
-                protectedField = "";
-                privateField = "";
-
-                WarnSerializableLambdaTest.packageClassMethod(null);
-                WarnSerializableLambdaTest.protectedClassMethod(null);
-                WarnSerializableLambdaTest.privateClassMethod(null);
-
-                packageInstanceMethod(null);
-                protectedInstanceMethod(null);
-                privateInstanceMethod(null);
-
-                PrivateClass.effectivelyNonPublicStaticField = "";
-                PrivateClass.effectivelyNonPublicClassMethod();
-
-                PrivateClass p = new PrivateClass();
-                p.effectivelyNonPublicInstanceField = "";
-                p.effectivelyNonPublicInstanceMethod();
-            }
-        };
-    }
-
-    void dontWarnLambda() throws Exception {
-        SAM t1 = (SAM & Serializable)WarnSerializableLambdaTest::publicClassMethod;
-
-        WarnSerializableLambdaTest test = new WarnSerializableLambdaTest();
-        SAM t2 = (SAM & Serializable)test::publicInstanceMethod;
-
-        int[] buffer = {0};
-
-        SAM t3 = (SAM & Serializable) param -> {
-            Object localVar;
-            localVar = null;
-            param = null;
-
-            WarnSerializableLambdaTest.staticPublicField = "";
-            publicField = "";
-            WarnSerializableLambdaTest.publicClassMethod(null);
-            publicInstanceMethod(null);
-
-            PublicClass.effectivelyPublicStaticField = "";
-            PublicClass.effectivelyPublicClassMethod();
-
-            PublicClass p = new PublicClass();
-            p.effectivelyPublicInstanceField = "";
-            p.effectivelyPublicInstanceMethod();
-
-            int l = buffer.length;
-
-            return null;
-        };
-    }
-
-    private void dontWarnAnoInnerClass() throws Exception {
-        final int[] buffer = {0};
-        new SerializableDesc() {
-            public void m(Object param) throws Exception {
-                Object localVar;
-                localVar = null;
-                param = null;
-
-                WarnSerializableLambdaTest.staticPublicField = "";
-                publicField = "";
-                WarnSerializableLambdaTest.publicClassMethod(null);
-                publicInstanceMethod(null);
-
-                PublicClass.effectivelyPublicStaticField = "";
-                PublicClass.effectivelyPublicClassMethod();
-
-                PublicClass p = new PublicClass();
-                p.effectivelyPublicInstanceField = "";
-                p.effectivelyPublicInstanceMethod();
-
-                int l = buffer.length;
-            }
-        };
-    }
-
-    enum WarnEnum {
-        A {
-            public void m() throws Exception {
-                WarnSerializableLambdaTest.staticPackageField = "";
-                WarnSerializableLambdaTest.staticProtectedField = "";
-                WarnSerializableLambdaTest.staticPrivateField = "";
-
-                WarnSerializableLambdaTest test =
-                        new WarnSerializableLambdaTest();
-
-                test.packageField = "";
-                test.protectedField = "";
-                test.privateField = "";
-
-                WarnSerializableLambdaTest.packageClassMethod(null);
-                WarnSerializableLambdaTest.protectedClassMethod(null);
-                WarnSerializableLambdaTest.privateClassMethod(null);
-
-                test.packageInstanceMethod(null);
-                test.protectedInstanceMethod(null);
-                test.privateInstanceMethod(null);
-
-                PrivateClass.effectivelyNonPublicStaticField = "";
-                PrivateClass.effectivelyNonPublicClassMethod();
-
-                PrivateClass p = new PrivateClass();
-                p.effectivelyNonPublicInstanceField = "";
-                p.effectivelyNonPublicInstanceMethod();
-            }
-        };
-
-        public void m() throws Exception {}
-    }
-
-    static String staticPackageField;
-    static private String staticPrivateField;
-    static protected String staticProtectedField;
-    static public String staticPublicField;
-
-    String packageField;
-    private String privateField;
-    protected String protectedField;
-    public String publicField;
-
-    static Object packageClassMethod(String s) {
-        return null;
-    }
-
-    static private Object privateClassMethod(String s) {
-        return null;
-    }
-
-    static protected Object protectedClassMethod(String s) {
-        return null;
-    }
-
-    static public Object publicClassMethod(String s) {
-        return null;
-    }
-
-    Object packageInstanceMethod(String s) {
-        return null;
-    }
-
-    protected Object protectedInstanceMethod(String s) {
-        return null;
-    }
-
-    private Object privateInstanceMethod(String s) {
-        return null;
-    }
-
-    public Object publicInstanceMethod(String s) {
-        return null;
-    }
-
-    interface SAM {
-        Object apply(String s) throws Exception;
-    }
-
-    interface SAM2 {
-        Object apply(String arg1, String arg2);
-    }
-
-    class SerializableDesc implements Serializable {
-        public void m(Object param) throws Exception {}
-    }
-
-    static private class PrivateClass {
-        static public String effectivelyNonPublicStaticField;
-        public String effectivelyNonPublicInstanceField;
-
-        static public void effectivelyNonPublicClassMethod() {}
-        public void effectivelyNonPublicInstanceMethod() {}
-    }
-
-    static public class PublicClass {
-        static public String effectivelyPublicStaticField;
-        public String effectivelyPublicInstanceField;
-
-        static public void effectivelyPublicClassMethod() {}
-        public void effectivelyPublicInstanceMethod() {}
-    }
-}
--- a/langtools/test/tools/javac/T8029102/WarnSerializableLambdaTest.out	Tue Oct 18 16:00:32 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-WarnSerializableLambdaTest.java:15:38: compiler.warn.access.to.sensitive.member.from.serializable.element: packageClassMethod(java.lang.String)
-WarnSerializableLambdaTest.java:16:38: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedClassMethod(java.lang.String)
-WarnSerializableLambdaTest.java:17:38: compiler.warn.access.to.sensitive.member.from.serializable.element: privateClassMethod(java.lang.String)
-WarnSerializableLambdaTest.java:20:38: compiler.warn.access.to.sensitive.member.from.serializable.element: packageInstanceMethod(java.lang.String)
-WarnSerializableLambdaTest.java:21:38: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedInstanceMethod(java.lang.String)
-WarnSerializableLambdaTest.java:22:38: compiler.warn.access.to.sensitive.member.from.serializable.element: privateInstanceMethod(java.lang.String)
-WarnSerializableLambdaTest.java:26:39: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPackageField
-WarnSerializableLambdaTest.java:27:39: compiler.warn.access.to.sensitive.member.from.serializable.element: staticProtectedField
-WarnSerializableLambdaTest.java:28:39: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPrivateField
-WarnSerializableLambdaTest.java:30:13: compiler.warn.access.to.sensitive.member.from.serializable.element: packageField
-WarnSerializableLambdaTest.java:31:13: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedField
-WarnSerializableLambdaTest.java:32:13: compiler.warn.access.to.sensitive.member.from.serializable.element: privateField
-WarnSerializableLambdaTest.java:34:39: compiler.warn.access.to.sensitive.member.from.serializable.element: packageClassMethod(java.lang.String)
-WarnSerializableLambdaTest.java:35:39: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedClassMethod(java.lang.String)
-WarnSerializableLambdaTest.java:36:39: compiler.warn.access.to.sensitive.member.from.serializable.element: privateClassMethod(java.lang.String)
-WarnSerializableLambdaTest.java:38:13: compiler.warn.access.to.sensitive.member.from.serializable.element: packageInstanceMethod(java.lang.String)
-WarnSerializableLambdaTest.java:39:13: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedInstanceMethod(java.lang.String)
-WarnSerializableLambdaTest.java:40:13: compiler.warn.access.to.sensitive.member.from.serializable.element: privateInstanceMethod(java.lang.String)
-WarnSerializableLambdaTest.java:42:25: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicStaticField
-WarnSerializableLambdaTest.java:43:25: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicClassMethod()
-WarnSerializableLambdaTest.java:46:14: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceField
-WarnSerializableLambdaTest.java:47:14: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceMethod()
-WarnSerializableLambdaTest.java:56:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPackageField
-WarnSerializableLambdaTest.java:57:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticProtectedField
-WarnSerializableLambdaTest.java:58:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPrivateField
-WarnSerializableLambdaTest.java:60:17: compiler.warn.access.to.sensitive.member.from.serializable.element: packageField
-WarnSerializableLambdaTest.java:61:17: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedField
-WarnSerializableLambdaTest.java:62:17: compiler.warn.access.to.sensitive.member.from.serializable.element: privateField
-WarnSerializableLambdaTest.java:64:43: compiler.warn.access.to.sensitive.member.from.serializable.element: packageClassMethod(java.lang.String)
-WarnSerializableLambdaTest.java:65:43: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedClassMethod(java.lang.String)
-WarnSerializableLambdaTest.java:66:43: compiler.warn.access.to.sensitive.member.from.serializable.element: privateClassMethod(java.lang.String)
-WarnSerializableLambdaTest.java:68:17: compiler.warn.access.to.sensitive.member.from.serializable.element: packageInstanceMethod(java.lang.String)
-WarnSerializableLambdaTest.java:69:17: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedInstanceMethod(java.lang.String)
-WarnSerializableLambdaTest.java:70:17: compiler.warn.access.to.sensitive.member.from.serializable.element: privateInstanceMethod(java.lang.String)
-WarnSerializableLambdaTest.java:72:29: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicStaticField
-WarnSerializableLambdaTest.java:73:29: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicClassMethod()
-WarnSerializableLambdaTest.java:76:18: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceField
-WarnSerializableLambdaTest.java:77:18: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceMethod()
-WarnSerializableLambdaTest.java:141:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPackageField
-WarnSerializableLambdaTest.java:142:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticProtectedField
-WarnSerializableLambdaTest.java:143:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPrivateField
-WarnSerializableLambdaTest.java:148:21: compiler.warn.access.to.sensitive.member.from.serializable.element: packageField
-WarnSerializableLambdaTest.java:149:21: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedField
-WarnSerializableLambdaTest.java:150:21: compiler.warn.access.to.sensitive.member.from.serializable.element: privateField
-WarnSerializableLambdaTest.java:152:43: compiler.warn.access.to.sensitive.member.from.serializable.element: packageClassMethod(java.lang.String)
-WarnSerializableLambdaTest.java:153:43: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedClassMethod(java.lang.String)
-WarnSerializableLambdaTest.java:154:43: compiler.warn.access.to.sensitive.member.from.serializable.element: privateClassMethod(java.lang.String)
-WarnSerializableLambdaTest.java:156:21: compiler.warn.access.to.sensitive.member.from.serializable.element: packageInstanceMethod(java.lang.String)
-WarnSerializableLambdaTest.java:157:21: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedInstanceMethod(java.lang.String)
-WarnSerializableLambdaTest.java:158:21: compiler.warn.access.to.sensitive.member.from.serializable.element: privateInstanceMethod(java.lang.String)
-WarnSerializableLambdaTest.java:160:29: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicStaticField
-WarnSerializableLambdaTest.java:161:29: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicClassMethod()
-WarnSerializableLambdaTest.java:164:18: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceField
-WarnSerializableLambdaTest.java:165:18: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceMethod()
-- compiler.err.warnings.and.werror
-1 error
-54 warnings
--- a/langtools/test/tools/javac/T8029102/WarnSerializableLambdaTestb.java	Tue Oct 18 16:00:32 2016 +0200
+++ b/langtools/test/tools/javac/T8029102/WarnSerializableLambdaTestb.java	Wed Mar 02 18:25:01 2016 -0500
@@ -4,7 +4,7 @@
  * @summary Enhance compiler warnings for Lambda
  *     Checks that the warning for accessing non public members of a class is
  *     fired correctly.
- * @compile/fail/ref=WarnSerializableLambdaTestb.out -XDrawDiagnostics -Werror -XDwarnOnAccessToSensitiveMembers WarnSerializableLambdaTestb.java
+ * @compile/fail/ref=WarnSerializableLambdaTestb.out -XDrawDiagnostics -Werror -XDwarnOnAccessToMembers WarnSerializableLambdaTestb.java
  */
 
 import java.io.Serializable;
--- a/langtools/test/tools/javac/T8029102/WarnSerializableLambdaTestb.out	Tue Oct 18 16:00:32 2016 +0200
+++ b/langtools/test/tools/javac/T8029102/WarnSerializableLambdaTestb.out	Wed Mar 02 18:25:01 2016 -0500
@@ -1,7 +1,5 @@
-WarnSerializableLambdaTestb.java:14:69: compiler.warn.access.to.sensitive.member.from.serializable.element: test()
-WarnSerializableLambdaTestb.java:18:69: compiler.warn.access.to.sensitive.member.from.serializable.element: test()
-WarnSerializableLambdaTestb.java:36:40: compiler.warn.access.to.sensitive.member.from.serializable.element: j
-WarnSerializableLambdaTestb.java:50:25: compiler.warn.access.to.sensitive.member.from.serializable.element: r
+WarnSerializableLambdaTestb.java:36:40: compiler.warn.access.to.member.from.serializable.element: j
+WarnSerializableLambdaTestb.java:50:25: compiler.warn.access.to.member.from.serializable.element: r
 - compiler.err.warnings.and.werror
 1 error
-4 warnings
+2 warnings
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8029102/WarnSerializableLambdaTestc.java	Wed Mar 02 18:25:01 2016 -0500
@@ -0,0 +1,20 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8026721
+ * @summary Enhance Lambda serialization
+ *     Checks that the warning for accessing non public members of a class is fired correctly.
+ * @compile -Xlint:serial -Werror WarnSerializableLambdaTestc.java
+ */
+
+import javax.tools.SimpleJavaFileObject;
+import java.io.Serializable;
+
+public class WarnSerializableLambdaTestc {
+    public interface SerializableIntf<T> extends Serializable {
+        String get(T o);
+    }
+
+    private void dontWarn() {
+        SerializableIntf<SimpleJavaFileObject> s = SimpleJavaFileObject::getName;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T8029102/WarnSerializableLambdaTestc.out	Wed Mar 02 18:25:01 2016 -0500
@@ -0,0 +1,4 @@
+WarnSerializableLambdaTestc.java:18:52: compiler.warn.access.to.member.from.serializable.lambda
+- compiler.err.warnings.and.werror
+1 error
+1 warning
--- a/langtools/test/tools/javac/diags/CheckResourceKeys.java	Tue Oct 18 16:00:32 2016 +0200
+++ b/langtools/test/tools/javac/diags/CheckResourceKeys.java	Wed Mar 02 18:25:01 2016 -0500
@@ -257,6 +257,8 @@
                 // ignore package and class names
                 if (cs.matches("(com|java|javax|jdk|sun)\\.[A-Za-z.]+"))
                     continue;
+                if (cs.matches("(java|javax|sun)\\."))
+                    continue;
                 // ignore debug flag names
                 if (cs.startsWith("debug."))
                     continue;
--- a/langtools/test/tools/javac/diags/examples.not-yet.txt	Tue Oct 18 16:00:32 2016 +0200
+++ b/langtools/test/tools/javac/diags/examples.not-yet.txt	Wed Mar 02 18:25:01 2016 -0500
@@ -111,6 +111,7 @@
 compiler.err.cant.inherit.from.anon                     # error for subclass of anonymous class
 compiler.misc.bad.class.file                            # class file is malformed
 compiler.misc.bad.const.pool.entry                      # constant pool entry has wrong type
+compiler.warn.access.to.member.from.serializable.lambda # in order to generate it we need to modify a restricted package
 
 # The following module-related messages will have to stay on the not-yet list for various reasons:
 compiler.warn.locn.unknown.file.on.module.path                # Never issued ATM (short circuited with an if (false))
--- a/langtools/test/tools/javac/diags/examples/WarnSerializableLambda.java	Tue Oct 18 16:00:32 2016 +0200
+++ b/langtools/test/tools/javac/diags/examples/WarnSerializableLambda.java	Wed Mar 02 18:25:01 2016 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, 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
@@ -21,21 +21,24 @@
  * questions.
  */
 
-// key: compiler.warn.access.to.sensitive.member.from.serializable.element
-// options: -XDwarnOnAccessToSensitiveMembers
+// key: compiler.warn.access.to.member.from.serializable.element
+// options: -XDwarnOnAccessToMembers
 
 import java.io.Serializable;
 
 public class WarnSerializableLambda {
-    interface SAM {
-        void apply(String s);
-    }
-
     private void m1() {
-        SAM s = (SAM & Serializable) c -> {
-            packageField = "";
+        new SerializableClass() {
+            @Override
+            public void m() {
+                packageField = "";
+            }
         };
     }
 
     String packageField;
+
+    class SerializableClass implements Serializable {
+        public void m() {}
+    }
 }