From 09e68e7510e01d623b77b884385308e808c4b90e Mon Sep 17 00:00:00 2001 From: Vaishnav Anil Date: Fri, 25 Jun 2021 05:07:14 +0530 Subject: [PATCH 1/2] Extracted URLClassLoader out of try-with-resources block --- src/main/java/me/clip/placeholderapi/util/FileUtil.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/util/FileUtil.java b/src/main/java/me/clip/placeholderapi/util/FileUtil.java index 6bed142..b98770f 100644 --- a/src/main/java/me/clip/placeholderapi/util/FileUtil.java +++ b/src/main/java/me/clip/placeholderapi/util/FileUtil.java @@ -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 matches = new ArrayList<>(); final List> 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(); From df8583df57489ec5cf8308abf11a0024b34431d5 Mon Sep 17 00:00:00 2001 From: Vaishnav Anil Date: Fri, 25 Jun 2021 05:08:14 +0530 Subject: [PATCH 2/2] Close URLClassLoader if Expansion class was not found --- src/main/java/me/clip/placeholderapi/util/FileUtil.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/util/FileUtil.java b/src/main/java/me/clip/placeholderapi/util/FileUtil.java index b98770f..825ff54 100644 --- a/src/main/java/me/clip/placeholderapi/util/FileUtil.java +++ b/src/main/java/me/clip/placeholderapi/util/FileUtil.java @@ -67,8 +67,11 @@ public class FileUtil { } } } - - return classes.isEmpty() ? null : classes.get(0); + if (classes.isEmpty()) { + loader.close(); + return null; + } + return classes.get(0); } }