author | duke |
Wed, 05 Jul 2017 22:05:30 +0200 | |
changeset 40321 | 4ad540e56bde |
parent 21648 | b485e4eb2fd9 |
permissions | -rw-r--r-- |
18234
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
1 |
/* |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
4 |
* |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
8 |
* |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
13 |
* accompanied this code). |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
14 |
* |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
18 |
* |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
21 |
* questions. |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
22 |
*/ |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
23 |
|
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
24 |
import java.io.InputStream; |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
25 |
import java.nio.file.Files; |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
26 |
import java.nio.file.Path; |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
27 |
import java.nio.file.Paths; |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
28 |
import java.nio.file.StandardCopyOption; |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
29 |
|
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
30 |
/** |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
31 |
* Dump a class file for a class on the class path in the current directory |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
32 |
*/ |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
33 |
public class ClassFileInstaller { |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
34 |
/** |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
35 |
* @param args The names of the classes to dump |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
36 |
* @throws Exception |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
37 |
*/ |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
38 |
public static void main(String... args) throws Exception { |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
39 |
for (String arg : args) { |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
40 |
ClassLoader cl = ClassFileInstaller.class.getClassLoader(); |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
41 |
|
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
42 |
// Convert dotted class name to a path to a class file |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
43 |
String pathName = arg.replace('.', '/').concat(".class"); |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
44 |
InputStream is = cl.getResourceAsStream(pathName); |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
45 |
|
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
46 |
// Create the class file's package directory |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
47 |
Path p = Paths.get(pathName); |
21648
b485e4eb2fd9
8027803: test/sun/reflect/AnonymousNewInstance/ManyNewInstanceAnonTest.java fails
rfield
parents:
18234
diff
changeset
|
48 |
Path parent = p.getParent(); |
b485e4eb2fd9
8027803: test/sun/reflect/AnonymousNewInstance/ManyNewInstanceAnonTest.java fails
rfield
parents:
18234
diff
changeset
|
49 |
if (parent != null) { |
b485e4eb2fd9
8027803: test/sun/reflect/AnonymousNewInstance/ManyNewInstanceAnonTest.java fails
rfield
parents:
18234
diff
changeset
|
50 |
Files.createDirectories(parent); |
b485e4eb2fd9
8027803: test/sun/reflect/AnonymousNewInstance/ManyNewInstanceAnonTest.java fails
rfield
parents:
18234
diff
changeset
|
51 |
} |
18234
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
52 |
// Create the class file |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
53 |
Files.copy(is, p, StandardCopyOption.REPLACE_EXISTING); |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
54 |
} |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
55 |
} |
996e8c4c858d
8007812: (reflect) Class.getEnclosingMethod problematic for some classes
jfranck
parents:
diff
changeset
|
56 |
} |