Merge pull request #649 from Vshnv/patch/expansion-classloader

Fixed issue with expansions not being able to access their resources
This commit is contained in:
PiggyPiglet 2021-06-25 22:11:58 +08:00 committed by GitHub
commit 8c69a164b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,13 +42,11 @@ public class FileUtil {
} }
final URL jar = file.toURI().toURL(); final URL jar = file.toURI().toURL();
final URLClassLoader loader = new URLClassLoader(new URL[]{jar}, clazz.getClassLoader());
final List<String> matches = new ArrayList<>(); final List<String> matches = new ArrayList<>();
final List<Class<? extends T>> classes = new ArrayList<>(); final List<Class<? extends T>> classes = new ArrayList<>();
try (final JarInputStream stream = new JarInputStream( try (final JarInputStream stream = new JarInputStream(jar.openStream())) {
jar.openStream()); final URLClassLoader loader = new URLClassLoader(new URL[]{jar},
clazz.getClassLoader())) {
JarEntry entry; JarEntry entry;
while ((entry = stream.getNextJarEntry()) != null) { while ((entry = stream.getNextJarEntry()) != null) {
final String name = entry.getName(); final String name = entry.getName();
@ -69,8 +67,11 @@ public class FileUtil {
} }
} }
} }
if (classes.isEmpty()) {
return classes.isEmpty() ? null : classes.get(0); loader.close();
return null;
}
return classes.get(0);
} }
} }