From 7fd6191ed22f7a6b34c1b0adeff6e5470453db81 Mon Sep 17 00:00:00 2001 From: Stefan Spieker Date: Fri, 11 Jun 2021 22:34:07 +0200 Subject: [PATCH] use try with resources --- core/src/main/java/hudson/PluginManager.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/hudson/PluginManager.java b/core/src/main/java/hudson/PluginManager.java index 2939186379da..256a4e29efa4 100644 --- a/core/src/main/java/hudson/PluginManager.java +++ b/core/src/main/java/hudson/PluginManager.java @@ -110,7 +110,6 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; import java.io.ByteArrayInputStream; -import java.io.Closeable; import java.io.File; import java.io.FilenameFilter; import java.io.IOException; @@ -482,8 +481,7 @@ private void addTo(List dependencies, List r) { } @Override - protected void reactOnCycle(PluginWrapper q, List cycle) - throws hudson.util.CyclicGraphDetector.CycleDetectedException { + protected void reactOnCycle(PluginWrapper q, List cycle) { LOGGER.log(Level.SEVERE, "found cycle in plugin dependencies: (root=" + q + ", deactivating all involved) " + cycle.stream().map(Object::toString).collect(Collectors.joining(" -> "))); for (PluginWrapper pluginWrapper : cycle) { @@ -1071,8 +1069,7 @@ protected void copyBundledPlugin(URL src, String fileName) throws IOException { } /*package*/ static @CheckForNull Manifest parsePluginManifest(URL bundledJpi) { - try { - URLClassLoader cl = new URLClassLoader(new URL[]{bundledJpi}); + try (URLClassLoader cl = new URLClassLoader(new URL[]{bundledJpi})){ InputStream in=null; try { URL res = cl.findResource(PluginWrapper.MANIFEST_FILENAME); @@ -1082,8 +1079,6 @@ protected void copyBundledPlugin(URL src, String fileName) throws IOException { } } finally { Util.closeAndLogFailures(in, LOGGER, PluginWrapper.MANIFEST_FILENAME, bundledJpi.toString()); - if (cl instanceof Closeable) - ((Closeable)cl).close(); } } catch (IOException e) { LOGGER.log(WARNING, "Failed to parse manifest of "+bundledJpi, e);