Repository: groovy Updated Branches: refs/heads/master dac1190d6 -> 2532d29e8
Close file and reader Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/2532d29e Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/2532d29e Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/2532d29e Branch: refs/heads/master Commit: 2532d29e887399633d165db4cb690dc1becc62d9 Parents: dac1190 Author: sunlan <[email protected]> Authored: Tue Dec 5 08:53:51 2017 +0800 Committer: sunlan <[email protected]> Committed: Tue Dec 5 08:53:51 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/2532d29e/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 81e0253..70f7b9f 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/2532d29e/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() } } }
