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
1 changed files with 7 additions and 6 deletions

View File

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