ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [1/6] ant git commit: Sonar false positives for resource leaks
Date Tue, 20 Dec 2016 19:52:51 GMT
Repository: ant
Updated Branches:
  refs/heads/master 990a664c4 -> 2bb5b057d


Sonar false positives for resource leaks


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

Branch: refs/heads/master
Commit: ac1b7652ddd5f4e01eb7e3e5e58f9d22900229a0
Parents: 8925f08
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Tue Dec 20 20:37:53 2016 +0100
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Tue Dec 20 20:39:52 2016 +0100

----------------------------------------------------------------------
 src/main/org/apache/tools/ant/Main.java                         | 5 ++++-
 src/main/org/apache/tools/ant/taskdefs/Truncate.java            | 4 ++--
 src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java   | 2 +-
 .../org/apache/tools/ant/taskdefs/optional/PropertyFile.java    | 2 +-
 .../org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java | 3 ++-
 .../apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java | 2 +-
 .../tools/ant/types/selectors/ContainsRegexpSelector.java       | 2 +-
 .../org/apache/tools/ant/types/selectors/ContainsSelector.java  | 4 ++--
 src/main/org/apache/tools/ant/util/FileUtils.java               | 2 +-
 src/main/org/apache/tools/zip/ZipFile.java                      | 4 +++-
 10 files changed, 18 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/Main.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java
index edce9c1..81e4ef1 100644
--- a/src/main/org/apache/tools/ant/Main.java
+++ b/src/main/org/apache/tools/ant/Main.java
@@ -355,7 +355,10 @@ public class Main implements AntMain {
                 try {
                     final File logFile = new File(args[i + 1]);
                     i++;
-                    logTo = new PrintStream(new FileOutputStream(logFile));
+                    // life-cycle of FileOutputStream is controlled by
+                    // logTo which becomes "out" and is closed in
+                    // handleLogfile
+                    logTo = new PrintStream(new FileOutputStream(logFile)); //NOSONAR
                     isLogFileUsed = true;
                 } catch (final IOException ioe) {
                     final String msg = "Cannot write on the specified log file. "

http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/taskdefs/Truncate.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Truncate.java b/src/main/org/apache/tools/ant/taskdefs/Truncate.java
index 6f43c05..cb8fd4a 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Truncate.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Truncate.java
@@ -167,7 +167,7 @@ public class Truncate extends Task {
         }
         RandomAccessFile raf = null;
         try {
-            raf = new RandomAccessFile(f, READ_WRITE);
+            raf = new RandomAccessFile(f, READ_WRITE); //NOSONAR
         } catch (Exception e) {
             throw new BuildException("Could not open " + f + " for writing", e);
         }
@@ -202,4 +202,4 @@ public class Truncate extends Task {
         return path;
     }
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java b/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
index a90bcc0..6f17402 100644
--- a/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
+++ b/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
@@ -299,7 +299,7 @@ public class CvsTagDiff extends AbstractCvsTask {
         BufferedReader reader = null;
 
         try {
-            reader = new BufferedReader(new FileReader(tmpFile));
+            reader = new BufferedReader(new FileReader(tmpFile)); //NOSONAR
 
             // entries are of the form:
             //CVS 1.11

http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java b/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
index 162cab1..7c778da 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
@@ -260,7 +260,7 @@ public class PropertyFile extends Task {
             throw new BuildException(x, getLocation());
         }
         try {
-            OutputStream os = new FileOutputStream(propertyfile);
+            OutputStream os = new FileOutputStream(propertyfile); //NOSONAR
             try {
                 try {
                     os.write(baos.toByteArray());

http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java
index 41e90d0..984fc37 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java
@@ -727,7 +727,8 @@ public class IPlanetEjbc {
                 } else {
                     location = (String) fileDtds.get(publicId);
                     if (location != null) {
-                        inputStream = new FileInputStream(location);
+                        // closed when the InputSource is closed
+                        inputStream = new FileInputStream(location); //NOSONAR
                     }
                 }
             } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java
index 21f03fe..9d2e9ae 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java
@@ -459,7 +459,7 @@ public class JDependTask extends Task {
         PrintWriter pw = null;
         if (getOutputFile() != null) {
             try {
-                fw = new FileWriter(getOutputFile().getPath());
+                fw = new FileWriter(getOutputFile().getPath()); //NOSONAR
             } catch (IOException e) {
                 String msg = "JDepend Failed when creating the output file: "
                     + e.getMessage();

http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java b/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java
index 4da3b6f..334f37e 100644
--- a/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java
+++ b/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java
@@ -184,7 +184,7 @@ public class ContainsRegexpSelector extends BaseExtendSelector
         }
 
         try {
-            in = new BufferedReader(new InputStreamReader(r.getInputStream()));
+            in = new BufferedReader(new InputStreamReader(r.getInputStream())); //NOSONAR
         } catch (Exception e) {
             throw new BuildException("Could not get InputStream from "
                     + r.toLongString(), e);

http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java b/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
index 6dabaf4..a1004a8 100644
--- a/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
+++ b/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
@@ -187,9 +187,9 @@ public class ContainsSelector extends BaseExtendSelector implements ResourceSele
         BufferedReader in = null;
         try {
             if (encoding != null) {
-                in = new BufferedReader(new InputStreamReader(r.getInputStream(), encoding));
+                in = new BufferedReader(new InputStreamReader(r.getInputStream(), encoding));
//NOSONAR
             }   else {
-                in = new BufferedReader(new InputStreamReader(r.getInputStream()));
+                in = new BufferedReader(new InputStreamReader(r.getInputStream())); //NOSONAR
             }
         } catch (Exception e) {
             throw new BuildException("Could not get InputStream from "

http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/util/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java
index bcef5ec..c2a60ed 100644
--- a/src/main/org/apache/tools/ant/util/FileUtils.java
+++ b/src/main/org/apache/tools/ant/util/FileUtils.java
@@ -1708,7 +1708,7 @@ public class FileUtils {
      */
     public String getDefaultEncoding() {
         InputStreamReader is = new InputStreamReader(
-            new InputStream() {
+            new InputStream() { //NOSONAR
                 public int read() {
                     return -1;
                 }

http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/zip/ZipFile.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/zip/ZipFile.java b/src/main/org/apache/tools/zip/ZipFile.java
index f342310..1be53cd 100644
--- a/src/main/org/apache/tools/zip/ZipFile.java
+++ b/src/main/org/apache/tools/zip/ZipFile.java
@@ -370,8 +370,10 @@ public class ZipFile implements Closeable {
         final OffsetEntry offsetEntry = ((Entry) ze).getOffsetEntry();
         ZipUtil.checkRequestedFeatures(ze);
         final long start = offsetEntry.dataOffset;
+        // doesn't get closed if the method is not supported, but
+        // doesn't hold any resources either
         final BoundedInputStream bis =
-            new BoundedInputStream(start, ze.getCompressedSize());
+            new BoundedInputStream(start, ze.getCompressedSize()); //NOSONAR
         switch (ze.getMethod()) {
             case ZipEntry.STORED:
                 return bis;


Mime
View raw message