diff options
author | Alexander Kurtakov | 2017-12-14 12:19:20 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2017-12-14 14:15:07 +0000 |
commit | 9b4f5003d023e28cea08b608f76ef953c065e255 (patch) | |
tree | 57eb69f574bec5c85908591799ce0d70622181e0 | |
parent | fc3cfaf394ac7a6887da4bfc00caa3f50baf3a64 (diff) | |
download | rt.equinox.framework-9b4f5003d023e28cea08b608f76ef953c065e255.tar.gz rt.equinox.framework-9b4f5003d023e28cea08b608f76ef953c065e255.tar.xz rt.equinox.framework-9b4f5003d023e28cea08b608f76ef953c065e255.zip |
Bug 528712 - Move launcher BREE to 1.7I20171215-0930I20171215-0215I20171215-0120I20171214-2000
Silence resource warnings and handle zipfile with try-with-resources to
ensure it's closed.
Change-Id: Ic2d0601029fc03770920b52a28c0c2fa055a037d
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r-- | bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java index dff5953c2..72c08451a 100644 --- a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java +++ b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java @@ -647,6 +647,7 @@ public class Main { parent = appCL.getParent(); } else if (PARENT_CLASSLOADER_CURRENT.equalsIgnoreCase(type)) parent = this.getClass().getClassLoader(); + @SuppressWarnings("resource") URLClassLoader loader = new StartupClassLoader(bootPath, parent); Class<?> clazz = loader.loadClass(STARTER); Method method = clazz.getDeclaredMethod("run", String[].class, Runnable.class); //$NON-NLS-1$ @@ -2377,39 +2378,43 @@ public class Main { if (!clean) return splash.getAbsolutePath(); } - ZipFile file; - try { - file = new ZipFile(jarPath); + + try (ZipFile file = new ZipFile(jarPath)) { + ZipEntry entry = file.getEntry(jarEntry.replace(File.separatorChar, '/')); + if (entry == null) + return null; + InputStream input = null; + try { + input = file.getInputStream(entry); + } catch (IOException e) { + log("Exception opening splash: " + entry.getName() + " in JAR file: " + jarPath); //$NON-NLS-1$ //$NON-NLS-2$ + log(e); + return null; + } + new File(splash.getParent()).mkdirs(); + OutputStream output; + try { + output = new BufferedOutputStream(new FileOutputStream(splash)); + } catch (FileNotFoundException e) { + try { + input.close(); + } catch (IOException e1) { + // ignore + } + return null; + } + transferStreams(input, output); + try { + file.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return splash.exists() ? splash.getAbsolutePath() : null; } catch (IOException e) { log("Exception looking for " + jarEntry + " in JAR file: " + jarPath); //$NON-NLS-1$ //$NON-NLS-2$ log(e); return null; } - ZipEntry entry = file.getEntry(jarEntry.replace(File.separatorChar, '/')); - if (entry == null) - return null; - InputStream input = null; - try { - input = file.getInputStream(entry); - } catch (IOException e) { - log("Exception opening splash: " + entry.getName() + " in JAR file: " + jarPath); //$NON-NLS-1$ //$NON-NLS-2$ - log(e); - return null; - } - new File(splash.getParent()).mkdirs(); - OutputStream output; - try { - output = new BufferedOutputStream(new FileOutputStream(splash)); - } catch (FileNotFoundException e) { - try { - input.close(); - } catch (IOException e1) { - // ignore - } - return null; - } - transferStreams(input, output); - return splash.exists() ? splash.getAbsolutePath() : null; } /* |