Browse Source

Sonar false positives for resource leaks

master
Stefan Bodewig 8 years ago
parent
commit
ac1b7652dd
10 changed files with 18 additions and 12 deletions
  1. +4
    -1
      src/main/org/apache/tools/ant/Main.java
  2. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/Truncate.java
  3. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
  4. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
  5. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java
  6. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java
  7. +1
    -1
      src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java
  8. +2
    -2
      src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
  9. +1
    -1
      src/main/org/apache/tools/ant/util/FileUtils.java
  10. +3
    -1
      src/main/org/apache/tools/zip/ZipFile.java

+ 4
- 1
src/main/org/apache/tools/ant/Main.java View File

@@ -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. "


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/Truncate.java View File

@@ -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;
}

}
}

+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java View File

@@ -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


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java View File

@@ -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());


+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java View File

@@ -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) {


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java View File

@@ -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();


+ 1
- 1
src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java View File

@@ -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);


+ 2
- 2
src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java View File

@@ -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 "


+ 1
- 1
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -1708,7 +1708,7 @@ public class FileUtils {
*/
public String getDefaultEncoding() {
InputStreamReader is = new InputStreamReader(
new InputStream() {
new InputStream() { //NOSONAR
public int read() {
return -1;
}


+ 3
- 1
src/main/org/apache/tools/zip/ZipFile.java View File

@@ -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;


Loading…
Cancel
Save