langtools/test/tools/javac/T8029102/WarnSerializableLambdaTestb.java
author vromero
Mon, 28 Apr 2014 14:48:51 +0100
changeset 24219 e7dc661cafae
child 41629 9d203cde7d84
permissions -rw-r--r--
8029102: Enhance compiler warnings for Lambda Reviewed-by: briangoetz, jjg, jlahoda, ahgross
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24219
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
     1
/*
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
     2
 * @test /nodynamiccopyright/
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
     3
 * @bug 8029102
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
     4
 * @summary Enhance compiler warnings for Lambda
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
     5
 *     Checks that the warning for accessing non public members of a class is
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
     6
 *     fired correctly.
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
     7
 * @compile/fail/ref=WarnSerializableLambdaTestb.out -XDrawDiagnostics -Werror -XDwarnOnAccessToSensitiveMembers WarnSerializableLambdaTestb.java
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
     8
 */
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
     9
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    10
import java.io.Serializable;
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    11
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    12
public class WarnSerializableLambdaTestb {
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    13
     public void foo(Secret1 secret) {
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    14
         Object o = (Runnable & java.io.Serializable) () -> { secret.test(); };
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    15
     }
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    16
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    17
     public void bar(Secret2 secret) {
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    18
         Object o = (Runnable & java.io.Serializable) () -> { secret.test(); };
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    19
     }
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    20
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    21
     private class Secret1 {
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    22
         public void test() {}
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    23
     }
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    24
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    25
     static private class Secret2 {
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    26
         public void test() {}
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    27
     }
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    28
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    29
     class TestInner {
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    30
        private int j = 0;
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    31
        void m() {
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    32
            Serializable s = new Serializable() {
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    33
                int i;
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    34
                void m() {
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    35
                    i = 0;  // don't warn
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    36
                    System.out.println(j); //warn
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    37
                }
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    38
            };
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    39
        }
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    40
    }
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    41
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    42
    class TestInner2 {
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    43
        class W implements Serializable {
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    44
            public int p = 0;
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    45
            class I {
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    46
                public int r = 0;
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    47
                class K implements Serializable {
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    48
                    void m() {
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    49
                        p = 1;  // don't warn owner is serializable
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    50
                        r = 2;  // warn owner is not serializable
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    51
                    }
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    52
                }
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    53
            }
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    54
        }
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    55
    }
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents:
diff changeset
    56
}