author | dnsimon |
Fri, 28 Apr 2017 12:22:53 -0700 | |
changeset 44863 | fd3d9eac0619 |
parent 44840 | 2761d60c363f |
permissions | -rw-r--r-- |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
1 |
/* |
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
42338
diff
changeset
|
2 |
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
4 |
* |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
8 |
* |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
14 |
* |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
18 |
* |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
22 |
*/ |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
23 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
24 |
import java.io.FilePermission; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
25 |
import java.io.IOException; |
37794
7223f8ad31a5
8154182: Fix java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java to only use available modules
shurailine
parents:
36928
diff
changeset
|
26 |
import java.io.UncheckedIOException; |
44840
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
27 |
import java.lang.module.ModuleFinder; |
36511 | 28 |
import java.lang.reflect.AccessibleObject; |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
29 |
import java.lang.reflect.Field; |
36511 | 30 |
import java.lang.reflect.Modifier; |
31 |
import java.lang.reflect.InaccessibleObjectException; |
|
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
32 |
import java.lang.reflect.ReflectPermission; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
33 |
import java.net.URI; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
34 |
import java.nio.file.FileSystem; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
35 |
import java.nio.file.FileSystems; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
36 |
import java.nio.file.Files; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
37 |
import java.nio.file.Path; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
38 |
import java.security.CodeSource; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
39 |
import java.security.Permission; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
40 |
import java.security.PermissionCollection; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
41 |
import java.security.Permissions; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
42 |
import java.security.Policy; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
43 |
import java.security.ProtectionDomain; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
44 |
import java.util.ArrayList; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
45 |
import java.util.Arrays; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
46 |
import java.util.Collections; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
47 |
import java.util.Enumeration; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
48 |
import java.util.Iterator; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
49 |
import java.util.List; |
44840
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
50 |
import java.util.Set; |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
51 |
import java.util.PropertyPermission; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
52 |
import java.util.concurrent.atomic.AtomicBoolean; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
53 |
import java.util.concurrent.atomic.AtomicLong; |
44840
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
54 |
import java.util.stream.Collectors; |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
55 |
import java.util.stream.Stream; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
56 |
|
36511 | 57 |
import jdk.internal.module.Modules; |
58 |
||
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
59 |
/** |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
60 |
* @test |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
61 |
* @bug 8065552 |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
62 |
* @summary test that all public fields returned by getDeclaredFields() can |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
63 |
* be set accessible if the right permission is granted; this test |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
64 |
* loads all classes and get their declared fields |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
65 |
* and call setAccessible(false) followed by setAccessible(true); |
36511 | 66 |
* @modules java.base/jdk.internal.module |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38329
diff
changeset
|
67 |
* @run main/othervm --add-modules=ALL-SYSTEM FieldSetAccessibleTest UNSECURE |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38329
diff
changeset
|
68 |
* @run main/othervm --add-modules=ALL-SYSTEM FieldSetAccessibleTest SECURE |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
69 |
* |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
70 |
* @author danielfuchs |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
71 |
*/ |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
72 |
public class FieldSetAccessibleTest { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
73 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
74 |
static final List<String> cantread = new ArrayList<>(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
75 |
static final List<String> failed = new ArrayList<>(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
76 |
static final AtomicLong classCount = new AtomicLong(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
77 |
static final AtomicLong fieldCount = new AtomicLong(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
78 |
static long startIndex = 0; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
79 |
static long maxSize = Long.MAX_VALUE; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
80 |
static long maxIndex = Long.MAX_VALUE; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
81 |
static final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
82 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
83 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
84 |
// Test that all fields for any given class can be made accessibles |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
85 |
static void testSetFieldsAccessible(Class<?> c) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
86 |
Module self = FieldSetAccessibleTest.class.getModule(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
87 |
Module target = c.getModule(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
88 |
String pn = c.getPackageName(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
89 |
boolean exported = self.canRead(target) && target.isExported(pn, self); |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
90 |
for (Field f : c.getDeclaredFields()) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
91 |
fieldCount.incrementAndGet(); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
92 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
93 |
// setAccessible succeeds only if it's exported and the member |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
94 |
// is public and of a public class, or it's opened |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
95 |
// otherwise it would fail. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
96 |
boolean isPublic = Modifier.isPublic(f.getModifiers()) && |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
97 |
Modifier.isPublic(c.getModifiers()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
98 |
boolean access = (exported && isPublic) || target.isOpen(pn, self); |
36511 | 99 |
try { |
100 |
f.setAccessible(false); |
|
101 |
f.setAccessible(true); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
102 |
if (!access) { |
36511 | 103 |
throw new RuntimeException( |
104 |
String.format("Expected InaccessibleObjectException is not thrown " |
|
105 |
+ "for field %s in class %s%n", f.getName(), c.getName())); |
|
106 |
} |
|
107 |
} catch (InaccessibleObjectException expected) { |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
108 |
if (access) { |
36511 | 109 |
throw new RuntimeException(expected); |
110 |
} |
|
111 |
} |
|
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
112 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
113 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
114 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
115 |
// Performs a series of test on the given class. |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
116 |
// At this time, we only call testSetFieldsAccessible(c) |
36511 | 117 |
public static boolean test(Class<?> c, boolean addExports) { |
118 |
Module self = FieldSetAccessibleTest.class.getModule(); |
|
119 |
Module target = c.getModule(); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
120 |
String pn = c.getPackageName(); |
36511 | 121 |
boolean exported = self.canRead(target) && target.isExported(pn, self); |
122 |
if (addExports && !exported) { |
|
123 |
Modules.addExports(target, pn, self); |
|
124 |
exported = true; |
|
125 |
} |
|
126 |
||
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
127 |
classCount.incrementAndGet(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
128 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
129 |
// Call getDeclaredFields() and try to set their accessible flag. |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
130 |
testSetFieldsAccessible(c); |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
131 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
132 |
// add more tests here... |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
133 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
134 |
return c == Class.class; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
135 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
136 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
137 |
// Prints a summary at the end of the test. |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
138 |
static void printSummary(long secs, long millis, long nanos) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
139 |
System.out.println("Tested " + fieldCount.get() + " fields of " |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
140 |
+ classCount.get() + " classes in " |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
141 |
+ secs + "s " + millis + "ms " + nanos + "ns"); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
142 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
143 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
144 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
145 |
/** |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
146 |
* @param args the command line arguments: |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
147 |
* |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
148 |
* SECURE|UNSECURE [startIndex (default=0)] [maxSize (default=Long.MAX_VALUE)] |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
149 |
* |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
150 |
* @throws java.lang.Exception if the test fails |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
151 |
*/ |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
152 |
public static void main(String[] args) throws Exception { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
153 |
if (args == null || args.length == 0) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
154 |
args = new String[] {"SECURE", "0"}; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
155 |
} else if (args.length > 3) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
156 |
throw new RuntimeException("Expected at most one argument. Found " |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
157 |
+ Arrays.asList(args)); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
158 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
159 |
try { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
160 |
if (args.length > 1) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
161 |
startIndex = Long.parseLong(args[1]); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
162 |
if (startIndex < 0) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
163 |
throw new IllegalArgumentException("startIndex args[1]: " |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
164 |
+ startIndex); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
165 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
166 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
167 |
if (args.length > 2) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
168 |
maxSize = Long.parseLong(args[2]); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
169 |
if (maxSize <= 0) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
170 |
maxSize = Long.MAX_VALUE; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
171 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
172 |
maxIndex = (Long.MAX_VALUE - startIndex) < maxSize |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
173 |
? Long.MAX_VALUE : startIndex + maxSize; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
174 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
175 |
TestCase.valueOf(args[0]).run(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
176 |
} catch (OutOfMemoryError oome) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
177 |
System.err.println(classCount.get()); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
178 |
throw oome; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
179 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
180 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
181 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
182 |
public static void run(TestCase test) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
183 |
System.out.println("Testing " + test); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
184 |
test(listAllClassNames()); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
185 |
System.out.println("Passed " + test); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
186 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
187 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
188 |
static Iterable<String> listAllClassNames() { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
189 |
return new ClassNameJrtStreamBuilder(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
190 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
191 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
192 |
static void test(Iterable<String> iterable) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
193 |
final long start = System.nanoTime(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
194 |
boolean classFound = false; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
195 |
int index = 0; |
36511 | 196 |
for (String s : iterable) { |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
197 |
if (index == maxIndex) break; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
198 |
try { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
199 |
if (index < startIndex) continue; |
36511 | 200 |
if (test(s, false)) { |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
201 |
classFound = true; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
202 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
203 |
} finally { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
204 |
index++; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
205 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
206 |
} |
36511 | 207 |
|
208 |
// Re-test with all packages exported |
|
209 |
for (String s : iterable) { |
|
210 |
test(s, true); |
|
211 |
} |
|
212 |
||
213 |
classCount.set(classCount.get() / 2); |
|
214 |
fieldCount.set(fieldCount.get() / 2); |
|
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
215 |
long elapsed = System.nanoTime() - start; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
216 |
long secs = elapsed / 1000_000_000; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
217 |
long millis = (elapsed % 1000_000_000) / 1000_000; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
218 |
long nanos = elapsed % 1000_000; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
219 |
System.out.println("Unreadable path elements: " + cantread); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
220 |
System.out.println("Failed path elements: " + failed); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
221 |
printSummary(secs, millis, nanos); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
222 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
223 |
if (!failed.isEmpty()) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
224 |
throw new RuntimeException("Test failed for the following classes: " + failed); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
225 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
226 |
if (!classFound && startIndex == 0 && index < maxIndex) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
227 |
// this is just to verify that we have indeed parsed rt.jar |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
228 |
// (or the java.base module) |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
229 |
throw new RuntimeException("Test failed: Class.class not found..."); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
230 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
231 |
if (classCount.get() == 0 && startIndex == 0) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
232 |
throw new RuntimeException("Test failed: no class found?"); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
233 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
234 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
235 |
|
36511 | 236 |
static boolean test(String s, boolean addExports) { |
38329
254b331d0059
8157146: Add debug printlns to tests FieldSetAccessibleTest and VerifyJimage.java
sundar
parents:
37794
diff
changeset
|
237 |
String clsName = s.replace('/', '.').substring(0, s.length() - 6); |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
238 |
try { |
38329
254b331d0059
8157146: Add debug printlns to tests FieldSetAccessibleTest and VerifyJimage.java
sundar
parents:
37794
diff
changeset
|
239 |
System.out.println("Loading " + clsName); |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
240 |
final Class<?> c = Class.forName( |
38329
254b331d0059
8157146: Add debug printlns to tests FieldSetAccessibleTest and VerifyJimage.java
sundar
parents:
37794
diff
changeset
|
241 |
clsName, |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
242 |
false, |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
243 |
systemClassLoader); |
36511 | 244 |
return test(c, addExports); |
38329
254b331d0059
8157146: Add debug printlns to tests FieldSetAccessibleTest and VerifyJimage.java
sundar
parents:
37794
diff
changeset
|
245 |
} catch (VerifyError ve) { |
254b331d0059
8157146: Add debug printlns to tests FieldSetAccessibleTest and VerifyJimage.java
sundar
parents:
37794
diff
changeset
|
246 |
System.err.println("VerifyError for " + clsName); |
254b331d0059
8157146: Add debug printlns to tests FieldSetAccessibleTest and VerifyJimage.java
sundar
parents:
37794
diff
changeset
|
247 |
ve.printStackTrace(System.err); |
254b331d0059
8157146: Add debug printlns to tests FieldSetAccessibleTest and VerifyJimage.java
sundar
parents:
37794
diff
changeset
|
248 |
failed.add(s); |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
249 |
} catch (Exception t) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
250 |
t.printStackTrace(System.err); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
251 |
failed.add(s); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
252 |
} catch (NoClassDefFoundError e) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
253 |
e.printStackTrace(System.err); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
254 |
failed.add(s); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
255 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
256 |
return false; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
257 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
258 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
259 |
static class ClassNameJrtStreamBuilder implements Iterable<String>{ |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
260 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
261 |
final FileSystem jrt; |
37794
7223f8ad31a5
8154182: Fix java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java to only use available modules
shurailine
parents:
36928
diff
changeset
|
262 |
final Path root; |
44840
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
263 |
final Set<String> modules; |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
264 |
ClassNameJrtStreamBuilder() { |
44840
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
265 |
jrt = FileSystems.getFileSystem(URI.create("jrt:/")); |
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
266 |
root = jrt.getPath("/modules"); |
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
267 |
modules = systemModules(); |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
268 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
269 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
270 |
@Override |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
271 |
public Iterator<String> iterator() { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
272 |
try { |
37794
7223f8ad31a5
8154182: Fix java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java to only use available modules
shurailine
parents:
36928
diff
changeset
|
273 |
return Files.walk(root) |
7223f8ad31a5
8154182: Fix java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java to only use available modules
shurailine
parents:
36928
diff
changeset
|
274 |
.filter(p -> p.getNameCount() > 2) |
44840
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
275 |
.filter(p -> modules.contains(p.getName(1).toString())) |
37794
7223f8ad31a5
8154182: Fix java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java to only use available modules
shurailine
parents:
36928
diff
changeset
|
276 |
.map(p -> p.subpath(2, p.getNameCount())) |
7223f8ad31a5
8154182: Fix java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java to only use available modules
shurailine
parents:
36928
diff
changeset
|
277 |
.map(p -> p.toString()) |
7223f8ad31a5
8154182: Fix java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java to only use available modules
shurailine
parents:
36928
diff
changeset
|
278 |
.filter(s -> s.endsWith(".class") && !s.endsWith("module-info.class")) |
7223f8ad31a5
8154182: Fix java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java to only use available modules
shurailine
parents:
36928
diff
changeset
|
279 |
.iterator(); |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
280 |
} catch(IOException x) { |
37794
7223f8ad31a5
8154182: Fix java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java to only use available modules
shurailine
parents:
36928
diff
changeset
|
281 |
throw new UncheckedIOException("Unable to walk \"/modules\"", x); |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
282 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
283 |
} |
44840
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
284 |
|
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
285 |
/* |
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
286 |
* Filter deployment modules |
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
287 |
*/ |
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
288 |
static Set<String> systemModules() { |
44863
fd3d9eac0619
8179434: test/java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java fails due to JDK-8177845
dnsimon
parents:
44840
diff
changeset
|
289 |
Set<String> mods = Set.of("javafx.deploy", "jdk.deploy", "jdk.plugin", "jdk.javaws", |
fd3d9eac0619
8179434: test/java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java fails due to JDK-8177845
dnsimon
parents:
44840
diff
changeset
|
290 |
// All JVMCI packages other than jdk.vm.ci.services are dynamically |
fd3d9eac0619
8179434: test/java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java fails due to JDK-8177845
dnsimon
parents:
44840
diff
changeset
|
291 |
// exported to jdk.internal.vm.compiler and jdk.aot |
fd3d9eac0619
8179434: test/java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java fails due to JDK-8177845
dnsimon
parents:
44840
diff
changeset
|
292 |
"jdk.internal.vm.compiler", "jdk.aot" |
fd3d9eac0619
8179434: test/java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java fails due to JDK-8177845
dnsimon
parents:
44840
diff
changeset
|
293 |
); |
44840
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
294 |
return ModuleFinder.ofSystem().findAll().stream() |
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
295 |
.map(mref -> mref.descriptor().name()) |
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
296 |
.filter(mn -> !mods.contains(mn)) |
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
297 |
.collect(Collectors.toSet()); |
2761d60c363f
8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
mchung
parents:
44545
diff
changeset
|
298 |
} |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
299 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
300 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
301 |
// Test with or without a security manager |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
302 |
public static enum TestCase { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
303 |
UNSECURE, SECURE; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
304 |
public void run() throws Exception { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
305 |
System.out.println("Running test case: " + name()); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
306 |
Configure.setUp(this); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
307 |
FieldSetAccessibleTest.run(this); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
308 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
309 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
310 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
311 |
// A helper class to configure the security manager for the test, |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
312 |
// and bypass it when needed. |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
313 |
static class Configure { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
314 |
static Policy policy = null; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
315 |
static final ThreadLocal<AtomicBoolean> allowAll = new ThreadLocal<AtomicBoolean>() { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
316 |
@Override |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
317 |
protected AtomicBoolean initialValue() { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
318 |
return new AtomicBoolean(false); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
319 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
320 |
}; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
321 |
static void setUp(TestCase test) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
322 |
switch (test) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
323 |
case SECURE: |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
324 |
if (policy == null && System.getSecurityManager() != null) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
325 |
throw new IllegalStateException("SecurityManager already set"); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
326 |
} else if (policy == null) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
327 |
policy = new SimplePolicy(TestCase.SECURE, allowAll); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
328 |
Policy.setPolicy(policy); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
329 |
System.setSecurityManager(new SecurityManager()); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
330 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
331 |
if (System.getSecurityManager() == null) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
332 |
throw new IllegalStateException("No SecurityManager."); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
333 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
334 |
if (policy == null) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
335 |
throw new IllegalStateException("policy not configured"); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
336 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
337 |
break; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
338 |
case UNSECURE: |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
339 |
if (System.getSecurityManager() != null) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
340 |
throw new IllegalStateException("SecurityManager already set"); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
341 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
342 |
break; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
343 |
default: |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
344 |
throw new InternalError("No such testcase: " + test); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
345 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
346 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
347 |
static void doPrivileged(Runnable run) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
348 |
allowAll.get().set(true); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
349 |
try { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
350 |
run.run(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
351 |
} finally { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
352 |
allowAll.get().set(false); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
353 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
354 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
355 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
356 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
357 |
// A Helper class to build a set of permissions. |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
31673
diff
changeset
|
358 |
static final class PermissionsBuilder { |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
359 |
final Permissions perms; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
360 |
public PermissionsBuilder() { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
361 |
this(new Permissions()); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
362 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
363 |
public PermissionsBuilder(Permissions perms) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
364 |
this.perms = perms; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
365 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
366 |
public PermissionsBuilder add(Permission p) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
367 |
perms.add(p); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
368 |
return this; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
369 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
370 |
public PermissionsBuilder addAll(PermissionCollection col) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
371 |
if (col != null) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
372 |
for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
373 |
perms.add(e.nextElement()); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
374 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
375 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
376 |
return this; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
377 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
378 |
public Permissions toPermissions() { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
379 |
final PermissionsBuilder builder = new PermissionsBuilder(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
380 |
builder.addAll(perms); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
381 |
return builder.perms; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
382 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
383 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
384 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
385 |
// Policy for the test... |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
386 |
public static class SimplePolicy extends Policy { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
387 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
388 |
final Permissions permissions; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
389 |
final Permissions allPermissions; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
390 |
final ThreadLocal<AtomicBoolean> allowAll; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
391 |
public SimplePolicy(TestCase test, ThreadLocal<AtomicBoolean> allowAll) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
392 |
this.allowAll = allowAll; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
393 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
394 |
// Permission needed by the tested code exercised in the test |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
395 |
permissions = new Permissions(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
396 |
permissions.add(new RuntimePermission("fileSystemProvider")); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
397 |
permissions.add(new RuntimePermission("createClassLoader")); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
398 |
permissions.add(new RuntimePermission("closeClassLoader")); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
399 |
permissions.add(new RuntimePermission("getClassLoader")); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
400 |
permissions.add(new RuntimePermission("accessDeclaredMembers")); |
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
42338
diff
changeset
|
401 |
permissions.add(new RuntimePermission("accessSystemModules")); |
28066
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
402 |
permissions.add(new ReflectPermission("suppressAccessChecks")); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
403 |
permissions.add(new PropertyPermission("*", "read")); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
404 |
permissions.add(new FilePermission("<<ALL FILES>>", "read")); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
405 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
406 |
// these are used for configuring the test itself... |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
407 |
allPermissions = new Permissions(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
408 |
allPermissions.add(new java.security.AllPermission()); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
409 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
410 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
411 |
@Override |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
412 |
public boolean implies(ProtectionDomain domain, Permission permission) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
413 |
if (allowAll.get().get()) return allPermissions.implies(permission); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
414 |
if (permissions.implies(permission)) return true; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
415 |
if (permission instanceof java.lang.RuntimePermission) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
416 |
if (permission.getName().startsWith("accessClassInPackage.")) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
417 |
// add these along to the set of permission we have, when we |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
418 |
// discover that we need them. |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
419 |
permissions.add(permission); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
420 |
return true; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
421 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
422 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
423 |
return false; |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
424 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
425 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
426 |
@Override |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
427 |
public PermissionCollection getPermissions(CodeSource codesource) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
428 |
return new PermissionsBuilder().addAll(allowAll.get().get() |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
429 |
? allPermissions : permissions).toPermissions(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
430 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
431 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
432 |
@Override |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
433 |
public PermissionCollection getPermissions(ProtectionDomain domain) { |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
434 |
return new PermissionsBuilder().addAll(allowAll.get().get() |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
435 |
? allPermissions : permissions).toPermissions(); |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
436 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
437 |
} |
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
438 |
|
b0d490c01280
8066612: Add a test that will call getDeclaredFields() on all classes and try to set them accessible.
dfuchs
parents:
diff
changeset
|
439 |
} |