You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/12/05 01:59:09 UTC
[4/4] groovy git commit: Close file and reader
Close file and reader
(cherry picked from commit 2532d29)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/26810aa3
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/26810aa3
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/26810aa3
Branch: refs/heads/GROOVY_2_6_X
Commit: 26810aa3b902a226836ed0fee7ebb9ff4339fc6e
Parents: f8fee10
Author: sunlan <su...@apache.org>
Authored: Tue Dec 5 08:53:51 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Tue Dec 5 09:58:53 2017 +0800
----------------------------------------------------------------------
.../org/codehaus/groovy/ant/GroovycTest.java | 12 +++++-
.../tools/shell/util/PackageHelperImpl.groovy | 42 +++++++++++---------
2 files changed, 34 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/26810aa3/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java b/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java
index 8dae0aa..26b9790 100644
--- a/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java
+++ b/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java
@@ -86,13 +86,23 @@ public class GroovycTest extends GroovyTestCase {
}
final File result = new File(classDirectory + classname + "_Result.txt");
final char[] buffer = new char[10];
+ FileReader fr = null;
try {
- (new FileReader(result)).read(buffer);
+ fr = new FileReader(result);
+ fr.read(buffer);
assertEquals("OK.", new String(buffer).trim());
} catch (final FileNotFoundException fnfe) {
fail("File " + result.getName() + " should have been created but wasn't.");
} catch (final IOException ioe) {
fail("Error reading file " + result.getName() + ".");
+ } finally {
+ if (null != fr) {
+ try {
+ fr.close();
+ } catch (IOException e) {
+ fail("Error close file reader " + result.getName() + ".");
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/26810aa3/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/util/PackageHelperImpl.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/util/PackageHelperImpl.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/util/PackageHelperImpl.groovy
index 16018c8..85aeb91 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/util/PackageHelperImpl.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/util/PackageHelperImpl.groovy
@@ -430,29 +430,33 @@ Files.walkFileTree(fs.getPath('modules'),
JarFile jf = new JarFile(file)
- for (Enumeration e = jf.entries(); e.hasMoreElements();) {
- JarEntry entry = (JarEntry) e.nextElement()
+ try {
+ for (Enumeration e = jf.entries(); e.hasMoreElements();) {
+ JarEntry entry = (JarEntry) e.nextElement()
- if (entry == null) {
- continue
- }
+ if (entry == null) {
+ continue
+ }
- String name = entry.name
+ String name = entry.name
- // only use class files
- if (!name.endsWith(CLASS_SUFFIX)) {
- continue
- }
- // normal slash inside jars even on windows
- int lastslash = name.lastIndexOf('/')
- if (lastslash == -1 || name.substring(0, lastslash) != pathname) {
- continue
- }
- name = name.substring(lastslash + 1, name.length() - CLASS_SUFFIX.length())
- if (!name.matches(NAME_PATTERN)) {
- continue
+ // only use class files
+ if (!name.endsWith(CLASS_SUFFIX)) {
+ continue
+ }
+ // normal slash inside jars even on windows
+ int lastslash = name.lastIndexOf('/')
+ if (lastslash == -1 || name.substring(0, lastslash) != pathname) {
+ continue
+ }
+ name = name.substring(lastslash + 1, name.length() - CLASS_SUFFIX.length())
+ if (!name.matches(NAME_PATTERN)) {
+ continue
+ }
+ classes.add(name)
}
- classes.add(name)
+ } finally {
+ jf.close()
}
}
}