1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|
# HG changeset patch
# User andrew
# Date 1382719863 -3600
# Fri Oct 25 17:51:03 2013 +0100
# Node ID d4fca2113b280a7db03b67caae22e0ceafb51b89
# Parent 566f427de7079a0ed32c2f625c952dcc45c348e3
OPENJDK6-19: Fix test cases from 8010118 to work with OpenJDK 6
Reviewed-by: omajid
diff -r 566f427de707 -r d4fca2113b28 test/sun/reflect/CallerSensitive/CallerSensitiveFinder.java
--- jdk/test/sun/reflect/CallerSensitive/CallerSensitiveFinder.java Tue Jun 03 13:28:16 2008 -0700
+++ jdk/test/sun/reflect/CallerSensitive/CallerSensitiveFinder.java Fri Oct 25 17:51:03 2013 +0100
@@ -23,16 +23,12 @@
import com.sun.tools.classfile.*;
import static com.sun.tools.classfile.ConstantPool.*;
+
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
@@ -53,7 +49,7 @@
private static int numThreads = 3;
private static boolean verbose = false;
public static void main(String[] args) throws Exception {
- List<Path> classes = new ArrayList<>();
+ List<File> classes = new ArrayList<File>();
String testclasses = System.getProperty("test.classes", ".");
int i = 0;
while (i < args.length) {
@@ -61,11 +57,11 @@
if (arg.equals("-v")) {
verbose = true;
} else {
- Path p = Paths.get(testclasses, arg);
- if (!p.toFile().exists()) {
+ File f = new File(testclasses, arg);
+ if (!f.exists()) {
throw new IllegalArgumentException(arg + " does not exist");
}
- classes.add(p);
+ classes.add(f);
}
}
if (classes.isEmpty()) {
@@ -81,7 +77,7 @@
}
}
- private final List<String> csMethodsMissingAnnotation = new ArrayList<>();
+ private final List<String> csMethodsMissingAnnotation = new ArrayList<String>();
private final java.lang.reflect.Method mhnCallerSensitiveMethod;
public CallerSensitiveFinder(String... methods) throws Exception {
super(methods);
@@ -91,12 +87,114 @@
static java.lang.reflect.Method getIsCallerSensitiveMethod()
throws ClassNotFoundException, NoSuchMethodException
{
- Class<?> cls = Class.forName("java.lang.invoke.MethodHandleNatives");
+ Class<?> cls = CallerSensitiveFinder.class;
java.lang.reflect.Method m = cls.getDeclaredMethod("isCallerSensitiveMethod", Class.class, String.class);
m.setAccessible(true);
return m;
}
+ // Needs to match method in 7's java.lang.invoke.MethodHandleNatives
+ private static boolean isCallerSensitiveMethod(Class<?> defc, String method) {
+ if ("doPrivileged".equals(method) ||
+ "doPrivilegedWithCombiner".equals(method))
+ return defc == java.security.AccessController.class;
+ else if ("checkMemberAccess".equals(method))
+ return defc == java.lang.SecurityManager.class;
+ else if ("getUnsafe".equals(method))
+ return defc == sun.misc.Unsafe.class;
+ else if ("invoke".equals(method))
+ return defc == java.lang.reflect.Method.class;
+ else if ("get".equals(method) ||
+ "getBoolean".equals(method) ||
+ "getByte".equals(method) ||
+ "getChar".equals(method) ||
+ "getShort".equals(method) ||
+ "getInt".equals(method) ||
+ "getLong".equals(method) ||
+ "getFloat".equals(method) ||
+ "getDouble".equals(method) ||
+ "set".equals(method) ||
+ "setBoolean".equals(method) ||
+ "setByte".equals(method) ||
+ "setChar".equals(method) ||
+ "setShort".equals(method) ||
+ "setInt".equals(method) ||
+ "setLong".equals(method) ||
+ "setFloat".equals(method) ||
+ "setDouble".equals(method))
+ return defc == java.lang.reflect.Field.class;
+ else if ("newInstance".equals(method)) {
+ if (defc == java.lang.reflect.Constructor.class) return true;
+ if (defc == java.lang.Class.class) return true;
+ } else if ("getFields".equals(method))
+ return defc == java.lang.Class.class ||
+ defc == javax.sql.rowset.serial.SerialJavaObject.class;
+ else if ("forName".equals(method) ||
+ "getClassLoader".equals(method) ||
+ "getClasses".equals(method) ||
+ "getMethods".equals(method) ||
+ "getConstructors".equals(method) ||
+ "getDeclaredClasses".equals(method) ||
+ "getDeclaredFields".equals(method) ||
+ "getDeclaredMethods".equals(method) ||
+ "getDeclaredConstructors".equals(method) ||
+ "getField".equals(method) ||
+ "getMethod".equals(method) ||
+ "getConstructor".equals(method) ||
+ "getDeclaredField".equals(method) ||
+ "getDeclaredMethod".equals(method) ||
+ "getDeclaredConstructor".equals(method) ||
+ "getDeclaringClass".equals(method) ||
+ "getEnclosingClass".equals(method) ||
+ "getEnclosingMethod".equals(method) ||
+ "getEnclosingConstructor".equals(method))
+ return defc == java.lang.Class.class;
+ else if ("getConnection".equals(method) ||
+ "getDriver".equals(method) ||
+ "getDrivers".equals(method) ||
+ "deregisterDriver".equals(method))
+ return defc == java.sql.DriverManager.class;
+ else if ("newUpdater".equals(method)) {
+ if (defc == java.util.concurrent.atomic.AtomicIntegerFieldUpdater.class) return true;
+ if (defc == java.util.concurrent.atomic.AtomicLongFieldUpdater.class) return true;
+ if (defc == java.util.concurrent.atomic.AtomicReferenceFieldUpdater.class) return true;
+ } else if ("getContextClassLoader".equals(method))
+ return defc == java.lang.Thread.class;
+ else if ("getPackage".equals(method) ||
+ "getPackages".equals(method))
+ return defc == java.lang.Package.class;
+ else if ("getParent".equals(method) ||
+ "getSystemClassLoader".equals(method))
+ return defc == java.lang.ClassLoader.class;
+ else if ("load".equals(method) ||
+ "loadLibrary".equals(method)) {
+ if (defc == java.lang.Runtime.class) return true;
+ if (defc == java.lang.System.class) return true;
+ } else if ("getCallerClass".equals(method)) {
+ if (defc == sun.reflect.Reflection.class) return true;
+ if (defc == java.lang.System.class) return true;
+ } else if ("getCallerClassLoader".equals(method))
+ return defc == java.lang.ClassLoader.class;
+ else if ("registerAsParallelCapable".equals(method))
+ return defc == java.lang.ClassLoader.class;
+ else if ("getInvocationHandler".equals(method) ||
+ "getProxyClass".equals(method) ||
+ "newProxyInstance".equals(method))
+ return defc == java.lang.reflect.Proxy.class;
+ else if ("getBundle".equals(method) ||
+ "clearCache".equals(method))
+ return defc == java.util.ResourceBundle.class;
+ else if ("getType".equals(method))
+ return defc == java.io.ObjectStreamField.class;
+ else if ("forClass".equals(method))
+ return defc == java.io.ObjectStreamClass.class;
+ else if ("getLogger".equals(method))
+ return defc == java.util.logging.Logger.class;
+ else if ("getAnonymousLogger".equals(method))
+ return defc == java.util.logging.Logger.class;
+ return false;
+ }
+
boolean inMethodHandlesList(String classname, String method) {
Class<?> cls;
try {
@@ -104,19 +202,21 @@
false,
ClassLoader.getSystemClassLoader());
return (Boolean) mhnCallerSensitiveMethod.invoke(null, cls, method);
- } catch (ClassNotFoundException|IllegalAccessException e) {
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e.getCause());
}
}
- public List<String> run(List<Path> classes) throws IOException, InterruptedException,
+ public List<String> run(List<File> classes) throws IOException, InterruptedException,
ExecutionException, ConstantPoolException
{
ExecutorService pool = Executors.newFixedThreadPool(numThreads);
- for (Path path : classes) {
- ClassFileReader reader = ClassFileReader.newInstance(path.toFile());
+ for (File path : classes) {
+ ClassFileReader reader = ClassFileReader.newInstance(path);
for (ClassFile cf : reader.getClassFiles()) {
String classFileName = cf.getName();
// for each ClassFile
@@ -192,56 +292,46 @@
}
static class PlatformClassPath {
- static List<Path> getJREClasses() throws IOException {
- List<Path> result = new ArrayList<Path>();
- Path home = Paths.get(System.getProperty("java.home"));
+ static List<File> getJREClasses() throws IOException {
+ List<File> result = new ArrayList<File>();
+ File home = new File(System.getProperty("java.home"));
- if (home.endsWith("jre")) {
+ if (home.toString().endsWith("jre")) {
// jar files in <javahome>/jre/lib
// skip <javahome>/lib
- result.addAll(addJarFiles(home.resolve("lib")));
- } else if (home.resolve("lib").toFile().exists()) {
+ result.addAll(addJarFiles(new File(home, "lib")));
+ } else if (new File(home, "lib").exists()) {
// either a JRE or a jdk build image
- File classes = home.resolve("classes").toFile();
+ File classes = new File(home, "classes");
if (classes.exists() && classes.isDirectory()) {
// jdk build outputdir
- result.add(classes.toPath());
+ result.add(classes);
}
// add other JAR files
- result.addAll(addJarFiles(home.resolve("lib")));
+ result.addAll(addJarFiles(new File(home, "lib")));
} else {
throw new RuntimeException("\"" + home + "\" not a JDK home");
}
return result;
}
- static List<Path> addJarFiles(final Path root) throws IOException {
- final List<Path> result = new ArrayList<Path>();
- final Path ext = root.resolve("ext");
- Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
- @Override
- public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
- throws IOException {
- if (dir.equals(root) || dir.equals(ext)) {
- return FileVisitResult.CONTINUE;
- } else {
- // skip other cobundled JAR files
- return FileVisitResult.SKIP_SUBTREE;
- }
- }
-
- @Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
- throws IOException {
- File f = file.toFile();
+ static List<File> addJarFiles(final File root) throws IOException {
+ final List<File> result = new ArrayList<File>();
+ final File ext = new File(root, "ext");
+ final List<File> files = new ArrayList<File>();
+ for (String s : root.list())
+ files.add(new File(root, s));
+ for (String s : ext.list())
+ files.add(new File(ext, s));
+ for (File f : files) {
+ if (f.isFile()) {
String fn = f.getName();
// parse alt-rt.jar as well
if (fn.endsWith(".jar") && !fn.equals("jfxrt.jar")) {
- result.add(file);
+ result.add(f);
}
- return FileVisitResult.CONTINUE;
}
- });
+ }
return result;
}
}
diff -r 566f427de707 -r d4fca2113b28 test/sun/reflect/CallerSensitive/ClassFileReader.java
--- jdk/test/sun/reflect/CallerSensitive/ClassFileReader.java Tue Jun 03 13:28:16 2008 -0700
+++ jdk/test/sun/reflect/CallerSensitive/ClassFileReader.java Fri Oct 25 17:51:03 2013 +0100
@@ -23,12 +23,8 @@
import com.sun.tools.classfile.ClassFile;
import com.sun.tools.classfile.ConstantPoolException;
+
import java.io.*;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -47,28 +43,28 @@
}
if (path.isDirectory()) {
- return new DirectoryReader(path.toPath());
+ return new DirectoryReader(path);
} else if (path.getName().endsWith(".jar")) {
- return new JarFileReader(path.toPath());
+ return new JarFileReader(path);
} else {
- return new ClassFileReader(path.toPath());
+ return new ClassFileReader(path);
}
}
/**
* Returns a ClassFileReader instance of a given JarFile.
*/
- public static ClassFileReader newInstance(Path path, JarFile jf) throws IOException {
+ public static ClassFileReader newInstance(File path, JarFile jf) throws IOException {
return new JarFileReader(path, jf);
}
- protected final Path path;
+ protected final File path;
protected final String baseFileName;
- private ClassFileReader(Path path) {
+ private ClassFileReader(File path) {
this.path = path;
- this.baseFileName = path.getFileName() != null
- ? path.getFileName().toString()
- : path.toString();
+ this.baseFileName = path.getName().equals("")
+ ? path.toString()
+ : path.getName();
}
public String getFileName() {
@@ -104,10 +100,10 @@
};
}
- protected ClassFile readClassFile(Path p) throws IOException {
+ protected ClassFile readClassFile(File p) throws IOException {
InputStream is = null;
try {
- is = Files.newInputStream(p);
+ is = new FileInputStream(p);
return ClassFile.read(is);
} catch (ConstantPoolException e) {
throw new ClassFileError(e);
@@ -150,7 +146,7 @@
}
private static class DirectoryReader extends ClassFileReader {
- DirectoryReader(Path path) throws IOException {
+ DirectoryReader(File path) throws IOException {
super(path);
}
@@ -158,17 +154,17 @@
if (name.indexOf('.') > 0) {
int i = name.lastIndexOf('.');
String pathname = name.replace('.', File.separatorChar) + ".class";
- Path p = path.resolve(pathname);
- if (!p.toFile().exists()) {
- p = path.resolve(pathname.substring(0, i) + "$" +
- pathname.substring(i+1, pathname.length()));
+ File p = new File(path, pathname);
+ if (!p.exists()) {
+ p = new File(path, pathname.substring(0, i) + "$" +
+ pathname.substring(i+1, pathname.length()));
}
- if (p.toFile().exists()) {
+ if (p.exists()) {
return readClassFile(p);
}
} else {
- Path p = path.resolve(name + ".class");
- if (p.toFile().exists()) {
+ File p = new File(path, name + ".class");
+ if (p.exists()) {
return readClassFile(p);
}
}
@@ -184,22 +180,24 @@
};
}
- private List<Path> walkTree(Path dir) throws IOException {
- final List<Path> files = new ArrayList<Path>();
- Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
- throws IOException {
- if (file.toFile().getName().endsWith(".class")) {
- files.add(file);
+ private List<File> walkTree(File dir) throws IOException {
+ final List<File> files = new ArrayList<File>();
+ final List<String> dirContents = Arrays.asList(dir.list());
+ for (String file : dirContents) {
+ File f = new File(dir, file);
+ if (f.isDirectory())
+ files.addAll(walkTree(f));
+ else {
+ if (f.getName().endsWith(".class")) {
+ files.add(f);
}
- return FileVisitResult.CONTINUE;
}
- });
+ }
return files;
}
class DirectoryIterator implements Iterator<ClassFile> {
- private List<Path> entries;
+ private List<File> entries;
private int index = 0;
DirectoryIterator() throws IOException {
entries = walkTree(path);
@@ -214,7 +212,7 @@
if (!hasNext()) {
throw new NoSuchElementException();
}
- Path path = entries.get(index++);
+ File path = entries.get(index++);
try {
return readClassFile(path);
} catch (IOException e) {
@@ -230,10 +228,10 @@
private static class JarFileReader extends ClassFileReader {
final JarFile jarfile;
- JarFileReader(Path path) throws IOException {
- this(path, new JarFile(path.toFile()));
+ JarFileReader(File path) throws IOException {
+ this(path, new JarFile(path));
}
- JarFileReader(Path path, JarFile jf) throws IOException {
+ JarFileReader(File path, JarFile jf) throws IOException {
super(path);
this.jarfile = jf;
}
diff -r 566f427de707 -r d4fca2113b28 test/sun/reflect/CallerSensitive/MethodFinder.java
--- jdk/test/sun/reflect/CallerSensitive/MethodFinder.java Tue Jun 03 13:28:16 2008 -0700
+++ jdk/test/sun/reflect/CallerSensitive/MethodFinder.java Fri Oct 25 17:51:03 2013 +0100
@@ -121,10 +121,6 @@
return false;
}
- public Boolean visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Void p) {
- return false;
- }
-
public Boolean visitLong(CONSTANT_Long_info info, Void p) {
return false;
}
@@ -133,14 +129,6 @@
return false;
}
- public Boolean visitMethodHandle(CONSTANT_MethodHandle_info info, Void p) {
- return false;
- }
-
- public Boolean visitMethodType(CONSTANT_MethodType_info info, Void p) {
- return false;
- }
-
public Boolean visitString(CONSTANT_String_info info, Void p) {
return false;
}
@@ -198,4 +186,3 @@
}
};
}
-
diff -r 566f427de707 -r d4fca2113b28 test/sun/reflect/CallerSensitive/MissingCallerSensitive.java
--- jdk/test/sun/reflect/CallerSensitive/MissingCallerSensitive.java Tue Jun 03 13:28:16 2008 -0700
+++ jdk/test/sun/reflect/CallerSensitive/MissingCallerSensitive.java Fri Oct 25 17:51:03 2013 +0100
@@ -30,14 +30,13 @@
* @run main/othervm MissingCallerSensitive
*/
-import java.nio.file.Path;
-import java.nio.file.Paths;
+import java.io.File;
import java.util.*;
public class MissingCallerSensitive {
public static void main(String[] args) throws Exception {
String testclasses = System.getProperty("test.classes", ".");
- List<Path> classes = new ArrayList<>();
- classes.add(Paths.get(testclasses, "MissingCallerSensitive.class"));
+ List<File> classes = new ArrayList<File>();
+ classes.add(new File(testclasses, "MissingCallerSensitive.class"));
final String method = "sun/reflect/Reflection.getCallerClass";
CallerSensitiveFinder csfinder = new CallerSensitiveFinder(method);
|