Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2017-01-04 14:42:26 +0000
committerStephan Herrmann2017-01-15 18:28:39 +0000
commit14841b4dead08757e17912c494ebf85483b743ac (patch)
treeca12d03b5a25e2dfdd3a13df6c983cd4c2b99b66
parentf5640ab06d952bd815fb5da104c1950a36094918 (diff)
downloadorg.eclipse.objectteams-14841b4dead08757e17912c494ebf85483b743ac.tar.gz
org.eclipse.objectteams-14841b4dead08757e17912c494ebf85483b743ac.tar.xz
org.eclipse.objectteams-14841b4dead08757e17912c494ebf85483b743ac.zip
Clean-up: use t-w-r where appropriate, maybe fixing some actual leaks
-rw-r--r--plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AddGlobalTeamActivationAdapter.java13
-rw-r--r--plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AsmWritableBoundClass.java20
-rw-r--r--plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/LoaderAwareClassWriter.java24
-rw-r--r--plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/WeavableRegionReader.java13
4 files changed, 20 insertions, 50 deletions
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AddGlobalTeamActivationAdapter.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AddGlobalTeamActivationAdapter.java
index a56ef0be6..88d805e6b 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AddGlobalTeamActivationAdapter.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AddGlobalTeamActivationAdapter.java
@@ -17,7 +17,6 @@ package org.eclipse.objectteams.otredyn.bytecode.asm;
import java.io.BufferedReader;
import java.io.FileInputStream;
-import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
@@ -146,10 +145,7 @@ public class AddGlobalTeamActivationAdapter extends ClassVisitor {
*/
private static List<String> getTeamsFromConfigFile() {
List<String> result = new ArrayList<String>();
- BufferedReader in = null;
- try {
- FileInputStream fstream = new FileInputStream(TEAM_CONFIG_FILE);
- in = new BufferedReader(new InputStreamReader(fstream));
+ try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(TEAM_CONFIG_FILE)))) {
while (in.ready()) {
String nextLine = in.readLine();
String nextTeam = nextLine.trim();
@@ -161,13 +157,6 @@ public class AddGlobalTeamActivationAdapter extends ClassVisitor {
}
} catch (Exception e) {
System.err.println("File input error: config file '" + TEAM_CONFIG_FILE + "' can not be found!");
- } finally {
- if (in != null)
- try {
- in.close();
- } catch (IOException e) {
- // nothing
- }
}
return result;
}
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AsmWritableBoundClass.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AsmWritableBoundClass.java
index 42be31d15..eee863b1b 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AsmWritableBoundClass.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AsmWritableBoundClass.java
@@ -18,7 +18,6 @@ package org.eclipse.objectteams.otredyn.bytecode.asm;
import java.io.File;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.lang.instrument.IllegalClassFormatException;
import java.util.ArrayList;
import java.util.List;
@@ -349,22 +348,15 @@ class AsmWritableBoundClass extends AsmBoundClass {
if (!dumping)
return;
- FileOutputStream fos = null;
- try {
- String name = getName().replaceAll("/", ".");
- File dir = new File("otdyn");
- if (!dir.exists())
- dir.mkdir();
- String filename = "otdyn/" + name + postfix+".#"+(n++);
- fos = new FileOutputStream(filename);
+ String name = getName().replaceAll("/", ".");
+ File dir = new File("otdyn");
+ if (!dir.exists())
+ dir.mkdir();
+ String filename = "otdyn/" + name + postfix+".#"+(n++);
+ try (FileOutputStream fos = new FileOutputStream(filename)) {
fos.write(bytecode);
} catch (Exception e) {
e.printStackTrace();
- } finally {
- if (fos != null)
- try {
- fos.close();
- } catch (IOException e) { /* ignore */}
}
}
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/LoaderAwareClassWriter.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/LoaderAwareClassWriter.java
index cbd9be913..260cd3299 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/LoaderAwareClassWriter.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/LoaderAwareClassWriter.java
@@ -58,14 +58,16 @@ public class LoaderAwareClassWriter extends ClassWriter {
ClassInformation ci2;
// need to load class bytes:
try {
- InputStream s1 = this.loader.getResourceAsStream(type1+".class");
- ci1 = this.analyzer.getClassInformation(s1, type1);
- if (ci1 == null)
- return OBJECT_SLASH;
- InputStream s2 = this.loader.getResourceAsStream(type2+".class");
- ci2 = this.analyzer.getClassInformation(s2, type2);
- if (ci2 == null)
- return OBJECT_SLASH;
+ try (InputStream s1 = this.loader.getResourceAsStream(type1+".class")) {
+ ci1 = this.analyzer.getClassInformation(s1, type1);
+ if (ci1 == null)
+ return OBJECT_SLASH;
+ }
+ try (InputStream s2 = this.loader.getResourceAsStream(type2+".class")) {
+ ci2 = this.analyzer.getClassInformation(s2, type2);
+ if (ci2 == null)
+ return OBJECT_SLASH;
+ }
} catch (Exception e) {
throw new RuntimeException(e.toString());
}
@@ -117,13 +119,11 @@ public class LoaderAwareClassWriter extends ClassWriter {
for (String type : types) {
ClassInformation ci = this.knownClasses.get(type);
if (ci == null) {
- InputStream s;
- try {
- s = this.loader.getResourceAsStream(type+".class");
+ try (InputStream s = this.loader.getResourceAsStream(type+".class")) {
+ ci = this.analyzer.getClassInformation(s, type);
} catch (Exception e) {
throw new RuntimeException(e.toString());
}
- ci = this.analyzer.getClassInformation(s, type);
this.knownClasses.put(type, ci);
}
if (ci != null) {
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/WeavableRegionReader.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/WeavableRegionReader.java
index dee53ca7e..b017b0559 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/WeavableRegionReader.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/WeavableRegionReader.java
@@ -17,7 +17,6 @@ package org.eclipse.objectteams.otredyn.bytecode.asm;
import java.io.BufferedReader;
import java.io.FileInputStream;
-import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
@@ -60,10 +59,7 @@ public class WeavableRegionReader {
if (WEAVABLE_FILE == null)
return Collections.emptyList();
List<String> result = new ArrayList<String>();
- BufferedReader in = null;
- try {
- FileInputStream fstream = new FileInputStream(WEAVABLE_FILE);
- in = new BufferedReader(new InputStreamReader(fstream));
+ try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(WEAVABLE_FILE)))) {
while (in.ready()) {
String nextLine = in.readLine();
String nextTeam = nextLine.trim();
@@ -75,13 +71,6 @@ public class WeavableRegionReader {
}
} catch (Exception e) {
System.err.println("File input error: weavable file '" + WEAVABLE_FILE + "' can not be found!");
- } finally {
- if (in != null)
- try {
- in.close();
- } catch (IOException e) {
- // nothing
- }
}
return result;
}

Back to the top