1 /* |
1 /* |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
35 |
38 |
36 static ClassLoader getContextClassLoader() { |
39 static ClassLoader getContextClassLoader() { |
37 if (System.getSecurityManager() == null) { |
40 if (System.getSecurityManager() == null) { |
38 return Thread.currentThread().getContextClassLoader(); |
41 return Thread.currentThread().getContextClassLoader(); |
39 } else { |
42 } else { |
40 return (ClassLoader) java.security.AccessController.doPrivileged( |
43 return AccessController.doPrivileged( |
41 new java.security.PrivilegedAction() { |
44 new PrivilegedAction<ClassLoader>() { |
42 public java.lang.Object run() { |
45 @Override |
|
46 public ClassLoader run() { |
43 return Thread.currentThread().getContextClassLoader(); |
47 return Thread.currentThread().getContextClassLoader(); |
44 } |
48 } |
45 }); |
49 }); |
46 } |
50 } |
47 } |
51 } |
48 |
52 |
49 static ClassLoader getClassClassLoader(final Class c) { |
53 static ClassLoader getClassClassLoader(final Class c) { |
50 if (System.getSecurityManager() == null) { |
54 if (System.getSecurityManager() == null) { |
51 return c.getClassLoader(); |
55 return c.getClassLoader(); |
52 } else { |
56 } else { |
53 return (ClassLoader) java.security.AccessController.doPrivileged( |
57 return AccessController.doPrivileged( |
54 new java.security.PrivilegedAction() { |
58 new PrivilegedAction<ClassLoader>() { |
55 public java.lang.Object run() { |
59 @Override |
|
60 public ClassLoader run() { |
56 return c.getClassLoader(); |
61 return c.getClassLoader(); |
57 } |
62 } |
58 }); |
63 }); |
59 } |
64 } |
60 } |
65 } |
61 |
66 |
62 static ClassLoader getSystemClassLoader() { |
67 static ClassLoader getSystemClassLoader() { |
63 if (System.getSecurityManager() == null) { |
68 if (System.getSecurityManager() == null) { |
64 return ClassLoader.getSystemClassLoader(); |
69 return ClassLoader.getSystemClassLoader(); |
65 } else { |
70 } else { |
66 return (ClassLoader) java.security.AccessController.doPrivileged( |
71 return AccessController.doPrivileged( |
67 new java.security.PrivilegedAction() { |
72 new PrivilegedAction<ClassLoader>() { |
68 public java.lang.Object run() { |
73 @Override |
|
74 public ClassLoader run() { |
69 return ClassLoader.getSystemClassLoader(); |
75 return ClassLoader.getSystemClassLoader(); |
70 } |
76 } |
71 }); |
77 }); |
72 } |
78 } |
73 } |
79 } |
74 |
80 |
75 static ClassLoader getParentClassLoader(final ClassLoader cl) { |
81 static ClassLoader getParentClassLoader(final ClassLoader cl) { |
76 if (System.getSecurityManager() == null) { |
82 if (System.getSecurityManager() == null) { |
77 return cl.getParent(); |
83 return cl.getParent(); |
78 } else { |
84 } else { |
79 return (ClassLoader) java.security.AccessController.doPrivileged( |
85 return AccessController.doPrivileged( |
80 new java.security.PrivilegedAction() { |
86 new PrivilegedAction<ClassLoader>() { |
81 public java.lang.Object run() { |
87 @Override |
|
88 public ClassLoader run() { |
82 return cl.getParent(); |
89 return cl.getParent(); |
83 } |
90 } |
84 }); |
91 }); |
85 } |
92 } |
86 } |
93 } |
87 |
94 |
88 static void setContextClassLoader(final ClassLoader cl) { |
95 static void setContextClassLoader(final ClassLoader cl) { |
89 if (System.getSecurityManager() == null) { |
96 if (System.getSecurityManager() == null) { |
90 Thread.currentThread().setContextClassLoader(cl); |
97 Thread.currentThread().setContextClassLoader(cl); |
91 } else { |
98 } else { |
92 java.security.AccessController.doPrivileged( |
99 AccessController.doPrivileged( |
93 new java.security.PrivilegedAction() { |
100 new PrivilegedAction<ClassLoader>() { |
94 public java.lang.Object run() { |
101 @Override |
|
102 public ClassLoader run() { |
95 Thread.currentThread().setContextClassLoader(cl); |
103 Thread.currentThread().setContextClassLoader(cl); |
96 return null; |
104 return null; |
97 } |
105 } |
98 }); |
106 }); |
99 } |
107 } |