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 00:39:23 UTC

groovy git commit: Close the buffered reader

Repository: groovy
Updated Branches:
  refs/heads/master cfbd6d298 -> dac1190d6


Close the buffered reader


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/dac1190d
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/dac1190d
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/dac1190d

Branch: refs/heads/master
Commit: dac1190d678717a74c44cb46c40f326a68b429cd
Parents: cfbd6d2
Author: sunlan <su...@apache.org>
Authored: Tue Dec 5 08:39:15 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Tue Dec 5 08:39:15 2017 +0800

----------------------------------------------------------------------
 .../codehaus/groovy/tools/FileSystemCompiler.java | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/dac1190d/src/main/org/codehaus/groovy/tools/FileSystemCompiler.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/tools/FileSystemCompiler.java b/src/main/org/codehaus/groovy/tools/FileSystemCompiler.java
index 26151a2..55d0ee3 100644
--- a/src/main/org/codehaus/groovy/tools/FileSystemCompiler.java
+++ b/src/main/org/codehaus/groovy/tools/FileSystemCompiler.java
@@ -240,15 +240,25 @@ public class FileSystemCompiler {
         boolean errors = false;
         for (String filename : filenames) {
             if (filename.startsWith("@")) {
+                String fn = filename.substring(1);
+                BufferedReader br = null;
                 try {
-                    BufferedReader br = new BufferedReader(new FileReader(filename.substring(1)));
-                    String file;
-                    while ((file = br.readLine()) != null) {
+                    br = new BufferedReader(new FileReader(fn));
+                    for (String file; (file = br.readLine()) != null; ) {
                         fileList.add(file);
                     }
                 } catch (IOException ioe) {
-                    System.err.println("error: file not readable: " + filename.substring(1));
+                    System.err.println("error: file not readable: " + fn);
                     errors = true;
+                } finally {
+                    if (null != br) {
+                        try {
+                            br.close();
+                        } catch (IOException e) {
+                            System.err.println("error: failed to close buffered reader: " + fn);
+                            errors = true;
+                        }
+                    }
                 }
             } else {
                 fileList.add(filename);