@@ -16,10 +16,6 @@ public class IsolatedClassLoader extends URLClassLoader {
16
16
17
17
private static boolean isEnabled = false ;
18
18
19
- public static boolean isEnabled () {
20
- return isEnabled ;
21
- }
22
-
23
19
static {
24
20
try {
25
21
Class <SkipIsolatedClassLoader > clazz = SkipIsolatedClassLoader .class ;
@@ -30,7 +26,7 @@ public static boolean isEnabled() {
30
26
31
27
private final Set <String > excludedClasses = new HashSet <>();
32
28
private final Set <String > excludedPackages = new HashSet <>();
33
-
29
+
34
30
private final MethodHandles .Lookup lookup = MethodHandles .lookup ();
35
31
private MethodHandle methodHandleTaboolibCommonRun ;
36
32
@@ -45,51 +41,49 @@ public IsolatedClassLoader(URL[] urls, ClassLoader parent) {
45
41
ServiceLoader <IsolatedClassLoaderConfig > serviceLoader = ServiceLoader .load (IsolatedClassLoaderConfig .class , parent );
46
42
for (IsolatedClassLoaderConfig config : serviceLoader ) {
47
43
Set <String > configExcludedClasses = config .excludedClasses ();
48
- if (configExcludedClasses != null && !configExcludedClasses .isEmpty ())
44
+ if (configExcludedClasses != null && !configExcludedClasses .isEmpty ()) {
49
45
excludedClasses .addAll (configExcludedClasses );
50
-
46
+ }
51
47
Set <String > configExcludedPackages = config .excludedPackages ();
52
- if (configExcludedPackages != null && !configExcludedPackages .isEmpty ())
48
+ if (configExcludedPackages != null && !configExcludedPackages .isEmpty ()) {
53
49
excludedPackages .addAll (configExcludedPackages );
50
+ }
54
51
}
55
52
}
56
-
53
+
57
54
@ Override
58
55
protected Class <?> loadClass (String name , boolean resolve ) throws ClassNotFoundException {
59
56
return loadClass (name , resolve , true );
60
57
}
61
58
62
59
public Class <?> loadClass (String name , boolean resolve , boolean checkParents ) throws ClassNotFoundException {
63
60
synchronized (getClassLoadingLock (name )) {
64
- Class <?> c = findLoadedClass (name );
65
-
61
+ Class <?> findClass = findLoadedClass (name );
66
62
// Check isolated classes and libraries before parent to:
67
63
// - prevent accessing classes of other plugins
68
64
// - prevent the usage of old patch classes (which stay in memory after reloading)
69
- if (c == null && !excludedClasses .contains (name )) {
65
+ if (findClass == null && !excludedClasses .contains (name )) {
70
66
boolean flag = true ;
71
67
for (String excludedPackage : excludedPackages ) {
72
68
if (name .startsWith (excludedPackage )) {
73
69
flag = false ;
74
70
break ;
75
71
}
76
72
}
77
- if (flag ) c = findClassOrNull (name );
73
+ if (flag ) {
74
+ findClass = findClassOrNull (name );
75
+ }
78
76
}
79
-
80
- if (c == null && checkParents ) {
81
- c = loadClassFromParentOrNull (name );
77
+ if (findClass == null && checkParents ) {
78
+ findClass = loadClassFromParentOrNull (name );
82
79
}
83
-
84
- if (c == null ) {
80
+ if (findClass == null ) {
85
81
throw new ClassNotFoundException (name );
86
82
}
87
-
88
83
if (resolve ) {
89
- resolveClass (c );
84
+ resolveClass (findClass );
90
85
}
91
-
92
- return c ;
86
+ return findClass ;
93
87
}
94
88
}
95
89
@@ -128,16 +122,16 @@ public void addExcludedPackages(Collection<String> names) {
128
122
public void runIsolated (Runnable target ) throws Throwable {
129
123
getMethodHandleTaboolibCommonRun ().invoke (target );
130
124
}
131
-
125
+
132
126
private MethodHandle getMethodHandleTaboolibCommonRun () throws ClassNotFoundException , NoSuchMethodException , IllegalAccessException {
133
127
if (methodHandleTaboolibCommonRun == null ) {
134
- methodHandleTaboolibCommonRun = lookup .findStatic (
135
- loadClass ("taboolib.common.TabooLibCommon" ),
136
- "run" ,
137
- MethodType .methodType (void .class , Runnable .class )
138
- );
128
+ methodHandleTaboolibCommonRun = lookup .findStatic (loadClass ("taboolib.common.TabooLibCommon" ), "run" , MethodType .methodType (void .class , Runnable .class ));
139
129
}
140
130
return methodHandleTaboolibCommonRun ;
141
131
}
142
-
132
+
133
+ public static boolean isEnabled () {
134
+ return isEnabled ;
135
+ }
143
136
}
137
+
0 commit comments