author | shurailine |
Thu, 03 Mar 2016 15:13:55 -0800 | |
changeset 36237 | 963d1115678b |
parent 33402 | 1156d495a525 |
child 36511 | 9d0388c6b336 |
permissions | -rw-r--r-- |
14762
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
1 |
/* |
36237
963d1115678b
8150998: Fix module dependences in java/lang tests
shurailine
parents:
33402
diff
changeset
|
2 |
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. |
14762
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
4 |
* |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
8 |
* |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
13 |
* accompanied this code). |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
14 |
* |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
18 |
* |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
21 |
* questions. |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
22 |
*/ |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
23 |
|
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
24 |
/* |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
25 |
* @test |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
26 |
* @bug 8003881 |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
27 |
* @summary tests DoPrivileged action (implemented as lambda expressions) by |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
28 |
* inserting them into the BootClassPath. |
33402
1156d495a525
8140336: Add @modules for exported dependencies to jdk_core tests
shurailine
parents:
30820
diff
changeset
|
29 |
* @modules jdk.compiler |
36237
963d1115678b
8150998: Fix module dependences in java/lang tests
shurailine
parents:
33402
diff
changeset
|
30 |
* jdk.zipfs |
16062
c64ef2b01401
8006000: TEST_BUG: java/lang/invoke/lambda/LambdaAccessControlTest.java fails intermittently
alanb
parents:
14762
diff
changeset
|
31 |
* @compile -XDignore.symbol.file LambdaAccessControlDoPrivilegedTest.java LUtils.java |
14762
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
32 |
* @run main/othervm LambdaAccessControlDoPrivilegedTest |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
33 |
*/ |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
34 |
import java.io.File; |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
35 |
import java.util.ArrayList; |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
36 |
import java.util.List; |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
37 |
|
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
38 |
public class LambdaAccessControlDoPrivilegedTest extends LUtils { |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
39 |
public static void main(String... args) { |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
40 |
final List<String> scratch = new ArrayList(); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
41 |
scratch.clear(); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
42 |
scratch.add("import java.security.*;"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
43 |
scratch.add("public class DoPriv {"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
44 |
scratch.add("public static void main(String... args) {"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
45 |
scratch.add("String prop = AccessController.doPrivileged((PrivilegedAction<String>) () -> {"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
46 |
scratch.add("return System.getProperty(\"user.home\");"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
47 |
scratch.add("});"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
48 |
scratch.add("}"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
49 |
scratch.add("}"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
50 |
File doprivJava = new File("DoPriv.java"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
51 |
File doprivClass = getClassFile(doprivJava); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
52 |
createFile(doprivJava, scratch); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
53 |
|
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
54 |
scratch.clear(); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
55 |
scratch.add("public class Bar {"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
56 |
scratch.add("public static void main(String... args) {"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
57 |
scratch.add("System.out.println(\"sun.boot.class.path\" + \"=\" +"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
58 |
scratch.add(" System.getProperty(\"sun.boot.class.path\", \"\"));"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
59 |
scratch.add("System.setSecurityManager(new SecurityManager());"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
60 |
scratch.add("DoPriv.main();"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
61 |
scratch.add("}"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
62 |
scratch.add("}"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
63 |
|
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
64 |
File barJava = new File("Bar.java"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
65 |
File barClass = getClassFile(barJava); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
66 |
createFile(barJava, scratch); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
67 |
|
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
68 |
String[] javacArgs = {barJava.getName(), doprivJava.getName()}; |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
69 |
compile(javacArgs); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
70 |
File jarFile = new File("foo.jar"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
71 |
String[] jargs = {"cvf", jarFile.getName(), doprivClass.getName()}; |
26635
2038308888ac
8058569: Update java/lang/invoke/lambda tests to eliminate dependency on sun.tools.jar.Main
dholmes
parents:
23010
diff
changeset
|
72 |
TestResult tr = doExec(JAR_CMD.getAbsolutePath(), |
2038308888ac
8058569: Update java/lang/invoke/lambda tests to eliminate dependency on sun.tools.jar.Main
dholmes
parents:
23010
diff
changeset
|
73 |
"cvf", jarFile.getName(), |
2038308888ac
8058569: Update java/lang/invoke/lambda tests to eliminate dependency on sun.tools.jar.Main
dholmes
parents:
23010
diff
changeset
|
74 |
doprivClass.getName()); |
2038308888ac
8058569: Update java/lang/invoke/lambda tests to eliminate dependency on sun.tools.jar.Main
dholmes
parents:
23010
diff
changeset
|
75 |
if (tr.exitValue != 0){ |
2038308888ac
8058569: Update java/lang/invoke/lambda tests to eliminate dependency on sun.tools.jar.Main
dholmes
parents:
23010
diff
changeset
|
76 |
throw new RuntimeException(tr.toString()); |
2038308888ac
8058569: Update java/lang/invoke/lambda tests to eliminate dependency on sun.tools.jar.Main
dholmes
parents:
23010
diff
changeset
|
77 |
} |
14762
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
78 |
doprivJava.delete(); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
79 |
doprivClass.delete(); |
26635
2038308888ac
8058569: Update java/lang/invoke/lambda tests to eliminate dependency on sun.tools.jar.Main
dholmes
parents:
23010
diff
changeset
|
80 |
tr = doExec(JAVA_CMD.getAbsolutePath(), |
30820 | 81 |
"-Xbootclasspath/a:foo.jar", |
26635
2038308888ac
8058569: Update java/lang/invoke/lambda tests to eliminate dependency on sun.tools.jar.Main
dholmes
parents:
23010
diff
changeset
|
82 |
"-cp", ".", "Bar"); |
14762
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
83 |
tr.assertZero("testDoPrivileged fails"); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
84 |
barJava.delete(); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
85 |
barClass.delete(); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
86 |
jarFile.delete(); |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
87 |
} |
34956da26ceb
8003881: Prevent lambda implementing inner classes from allowing the creation of new instances
rfield
parents:
diff
changeset
|
88 |
} |