diff options
author | Lars Vogel | 2021-04-09 11:09:40 +0000 |
---|---|---|
committer | Lars Vogel | 2021-04-09 11:09:40 +0000 |
commit | fb9784e6810b3d47444af881ba0ce8503ac25b37 (patch) | |
tree | 08acbe0b11b284f4051be216ca527c79d0903ba6 | |
parent | fb9ac60e730a61fa6cbcac206a246e530df65e0a (diff) | |
download | rt.equinox.framework-fb9784e6810b3d47444af881ba0ce8503ac25b37.tar.gz rt.equinox.framework-fb9784e6810b3d47444af881ba0ce8503ac25b37.tar.xz rt.equinox.framework-fb9784e6810b3d47444af881ba0ce8503ac25b37.zip |
[dogfooding] Try with resources applied to org.eclipse.osgi
Applied JDT try with resource cleanup to PDE, this cleanup
creates shorter code
Change-Id: I3bde6441b9117109cadd0c84c283074ffb5252a4
Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
3 files changed, 4 insertions, 16 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/FrameworkDebugOptions.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/FrameworkDebugOptions.java index cbea86156..8451ae285 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/FrameworkDebugOptions.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/FrameworkDebugOptions.java @@ -98,12 +98,9 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom } System.out.print("Debug options:\n " + optionsFile.toExternalForm()); //$NON-NLS-1$ try { - InputStream input = LocationHelper.getStream(optionsFile); - try { + try (InputStream input = LocationHelper.getStream(optionsFile)) { options.load(input); System.out.println(" loaded"); //$NON-NLS-1$ - } finally { - input.close(); } } catch (FileNotFoundException e) { System.out.println(" not found"); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java index f3ddd6297..70e7ea0b0 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java @@ -362,11 +362,8 @@ public class EquinoxConfiguration implements EnvironmentInfo { if (location == null) return result; try { - InputStream in = LocationHelper.getStream(location); - try { + try (InputStream in = LocationHelper.getStream(location)) { result.load(in); - } finally { - in.close(); } } catch (FileNotFoundException e) { // TODO probably should log, but the common case for non-eclipse diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java index 153aa9daf..860c4ad46 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java @@ -1459,8 +1459,7 @@ public class Storage { // create a temporary in memory stream so we can figure out the length ByteArrayOutputStream tempBytes = new ByteArrayOutputStream(); - DataOutputStream temp = new DataOutputStream(tempBytes); - try { + try (DataOutputStream temp = new DataOutputStream(tempBytes)) { Object saveContext = factory.createSaveContext(); for (Generation generation : generations) { if (generation.getBundleInfo().getBundleId() == 0) { @@ -1472,8 +1471,6 @@ public class Storage { hook.save(saveContext, temp); } } - } finally { - temp.close(); } out.writeInt(tempBytes.size()); out.write(tempBytes.toByteArray()); @@ -1612,8 +1609,7 @@ public class Storage { byte[] bytes = new byte[dataSize]; in.readFully(bytes); if (factory != null) { - DataInputStream temp = new DataInputStream(new ByteArrayInputStream(bytes)); - try { + try (DataInputStream temp = new DataInputStream(new ByteArrayInputStream(bytes))) { if (factory.isCompatibleWith(version)) { Object loadContext = factory.createLoadContext(version); for (Generation generation : generations) { @@ -1641,8 +1637,6 @@ public class Storage { } } catch (BundleException e) { throw new IOException(e); - } finally { - temp.close(); } } } |