groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [4/4] groovy git commit: Close file and reader
Date Tue, 05 Dec 2017 02:00:00 GMT
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/699d79bd
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/699d79bd
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/699d79bd

Branch: refs/heads/GROOVY_2_5_X
Commit: 699d79bd5ce9f15b533e1590a12b2d36212e732c
Parents: 04e3d1d
Author: sunlan <sunlan@apache.org>
Authored: Tue Dec 5 08:53:51 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Tue Dec 5 09:59: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/699d79bd/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/699d79bd/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()
                 }
             }
         }


Mime
View raw message