24219
|
1 |
/*
|
|
2 |
* @test /nodynamiccopyright/
|
|
3 |
* @bug 8029102
|
|
4 |
* @summary Enhance compiler warnings for Lambda
|
|
5 |
* Checks that the warning for accessing non public members of a class is
|
|
6 |
* fired correctly.
|
|
7 |
* @compile/fail/ref=WarnSerializableLambdaTestb.out -XDrawDiagnostics -Werror -XDwarnOnAccessToSensitiveMembers WarnSerializableLambdaTestb.java
|
|
8 |
*/
|
|
9 |
|
|
10 |
import java.io.Serializable;
|
|
11 |
|
|
12 |
public class WarnSerializableLambdaTestb {
|
|
13 |
public void foo(Secret1 secret) {
|
|
14 |
Object o = (Runnable & java.io.Serializable) () -> { secret.test(); };
|
|
15 |
}
|
|
16 |
|
|
17 |
public void bar(Secret2 secret) {
|
|
18 |
Object o = (Runnable & java.io.Serializable) () -> { secret.test(); };
|
|
19 |
}
|
|
20 |
|
|
21 |
private class Secret1 {
|
|
22 |
public void test() {}
|
|
23 |
}
|
|
24 |
|
|
25 |
static private class Secret2 {
|
|
26 |
public void test() {}
|
|
27 |
}
|
|
28 |
|
|
29 |
class TestInner {
|
|
30 |
private int j = 0;
|
|
31 |
void m() {
|
|
32 |
Serializable s = new Serializable() {
|
|
33 |
int i;
|
|
34 |
void m() {
|
|
35 |
i = 0; // don't warn
|
|
36 |
System.out.println(j); //warn
|
|
37 |
}
|
|
38 |
};
|
|
39 |
}
|
|
40 |
}
|
|
41 |
|
|
42 |
class TestInner2 {
|
|
43 |
class W implements Serializable {
|
|
44 |
public int p = 0;
|
|
45 |
class I {
|
|
46 |
public int r = 0;
|
|
47 |
class K implements Serializable {
|
|
48 |
void m() {
|
|
49 |
p = 1; // don't warn owner is serializable
|
|
50 |
r = 2; // warn owner is not serializable
|
|
51 |
}
|
|
52 |
}
|
|
53 |
}
|
|
54 |
}
|
|
55 |
}
|
|
56 |
}
|