Ensure extension JarFile is always properly closed.
@@ -216,14 +216,7 @@ public class ExtensionClassLoader extends URLClassLoader {
private static URL[] getExtensionURLs(File extension,
List<File> temporaryFiles) throws GuacamoleException {
- JarFile extensionJar;
- try {
- extensionJar = new JarFile(extension);
- }
- catch (IOException e) {
- throw new GuacamoleServerException("Contents of extension \""
- + extension + "\" cannot be read.", e);
- }
+ try (JarFile extensionJar = new JarFile(extension)) {
// Include extension itself within classpath
List<URL> urls = new ArrayList<>();
@@ -296,6 +289,12 @@ public class ExtensionClassLoader extends URLClassLoader {
return urls.toArray(new URL[0]);
+ }
+ catch (IOException e) {
+ throw new GuacamoleServerException("Contents of extension \""
+ + extension + "\" cannot be read.", e);
+ }
+
}
/**
