@@ -63,17 +63,16 @@ private ReflectUtils() {
63
63
64
64
private static final Method classLoaderDefineClassMethod ;
65
65
66
- private static final ProtectionDomain PROTECTION_DOMAIN ;
67
-
68
66
private static final Throwable THROWABLE ;
69
67
68
+ private static final ProtectionDomain PROTECTION_DOMAIN ;
69
+
70
70
private static final List <Method > OBJECT_METHODS = new ArrayList <Method >();
71
71
72
72
static {
73
73
Method privateLookupIn ;
74
74
Method lookupDefineClass ;
75
75
Method classLoaderDefineClass ;
76
- ProtectionDomain protectionDomain ;
77
76
Throwable throwable = null ;
78
77
try {
79
78
privateLookupIn = (Method ) AccessController .doPrivileged (new PrivilegedExceptionAction () {
@@ -102,39 +101,37 @@ public Object run() throws Exception {
102
101
String .class , byte [].class , Integer .TYPE , Integer .TYPE , ProtectionDomain .class );
103
102
}
104
103
});
105
- protectionDomain = getProtectionDomain (ReflectUtils .class );
106
- AccessController .doPrivileged (new PrivilegedExceptionAction () {
107
- public Object run () throws Exception {
108
- Method [] methods = Object .class .getDeclaredMethods ();
109
- for (Method method : methods ) {
110
- if ("finalize" .equals (method .getName ())
111
- || (method .getModifiers () & (Modifier .FINAL | Modifier .STATIC )) > 0 ) {
112
- continue ;
113
- }
114
- OBJECT_METHODS .add (method );
115
- }
116
- return null ;
117
- }
118
- });
119
104
}
120
105
catch (Throwable t ) {
121
106
privateLookupIn = null ;
122
107
lookupDefineClass = null ;
123
108
classLoaderDefineClass = null ;
124
- protectionDomain = null ;
125
109
throwable = t ;
126
110
}
111
+
127
112
privateLookupInMethod = privateLookupIn ;
128
113
lookupDefineClassMethod = lookupDefineClass ;
129
114
classLoaderDefineClassMethod = classLoaderDefineClass ;
130
- PROTECTION_DOMAIN = protectionDomain ;
131
115
THROWABLE = throwable ;
116
+ PROTECTION_DOMAIN = getProtectionDomain (ReflectUtils .class );
117
+
118
+ AccessController .doPrivileged (new PrivilegedAction () {
119
+ public Object run () {
120
+ Method [] methods = Object .class .getDeclaredMethods ();
121
+ for (Method method : methods ) {
122
+ if ("finalize" .equals (method .getName ())
123
+ || (method .getModifiers () & (Modifier .FINAL | Modifier .STATIC )) > 0 ) {
124
+ continue ;
125
+ }
126
+ OBJECT_METHODS .add (method );
127
+ }
128
+ return null ;
129
+ }
130
+ });
132
131
}
133
132
// SPRING PATCH END
134
133
135
- private static final String [] CGLIB_PACKAGES = {
136
- "java.lang" ,
137
- };
134
+ private static final String [] CGLIB_PACKAGES = {"java.lang" };
138
135
139
136
static {
140
137
primitives .put ("byte" , Byte .TYPE );
@@ -499,6 +496,7 @@ public static Class defineClass(String className, byte[] b, ClassLoader loader,
499
496
ProtectionDomain protectionDomain , Class <?> contextClass ) throws Exception {
500
497
501
498
Class c = null ;
499
+ Throwable t = THROWABLE ;
502
500
503
501
// Preferred option: JDK 9+ Lookup.defineClass API if ClassLoader matches
504
502
if (contextClass != null && contextClass .getClassLoader () == loader &&
@@ -516,6 +514,7 @@ public static Class defineClass(String className, byte[] b, ClassLoader loader,
516
514
// in case of plain LinkageError (class already defined)
517
515
// or IllegalArgumentException (class in different package):
518
516
// fall through to traditional ClassLoader.defineClass below
517
+ t = ex ;
519
518
}
520
519
catch (Throwable ex ) {
521
520
throw new CodeGenerationException (ex );
@@ -539,9 +538,11 @@ public static Class defineClass(String className, byte[] b, ClassLoader loader,
539
538
throw new CodeGenerationException (ex .getTargetException ());
540
539
}
541
540
// in case of UnsupportedOperationException, fall through
541
+ t = ex .getTargetException ();
542
542
}
543
543
catch (Throwable ex ) {
544
544
// publicDefineClass method not available -> fall through
545
+ t = ex ;
545
546
}
546
547
547
548
// Classic option: protected ClassLoader.defineClass method
@@ -562,6 +563,7 @@ public static Class defineClass(String className, byte[] b, ClassLoader loader,
562
563
if (!ex .getClass ().getName ().endsWith ("InaccessibleObjectException" )) {
563
564
throw new CodeGenerationException (ex );
564
565
}
566
+ t = ex ;
565
567
}
566
568
}
567
569
}
@@ -584,7 +586,7 @@ public static Class defineClass(String className, byte[] b, ClassLoader loader,
584
586
585
587
// No defineClass variant available at all?
586
588
if (c == null ) {
587
- throw new CodeGenerationException (THROWABLE );
589
+ throw new CodeGenerationException (t );
588
590
}
589
591
590
592
// Force static initializers to run.
0 commit comments