Merge pull request #382 from awhitford/MojoStreamClose

Removed unnecessary OutputStream closing.
This commit is contained in:
Jeremy Long
2015-10-25 06:04:28 -04:00

View File

@@ -931,20 +931,11 @@ public abstract class BaseDependencyCheckMojo extends AbstractMojo implements Ma
parent.getAbsolutePath())); parent.getAbsolutePath()));
} }
OutputStream os = null;
OutputStream bos = null;
ObjectOutputStream out = null; ObjectOutputStream out = null;
try { try {
if (dependencies != null) { if (dependencies != null) {
os = new FileOutputStream(file); out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
bos = new BufferedOutputStream(os);
out = new ObjectOutputStream(bos);
out.writeObject(dependencies); out.writeObject(dependencies);
out.flush();
//call reset to prevent resource leaks per
//https://www.securecoding.cert.org/confluence/display/java/SER10-J.+Avoid+memory+and+resource+leaks+during+serialization
out.reset();
} }
if (getLog().isDebugEnabled()) { if (getLog().isDebugEnabled()) {
getLog().debug(String.format("Serialized data file written to '%s' for %s, referenced by key %s", getLog().debug(String.format("Serialized data file written to '%s' for %s, referenced by key %s",
@@ -967,24 +958,6 @@ public abstract class BaseDependencyCheckMojo extends AbstractMojo implements Ma
} }
} }
} }
if (bos != null) {
try {
bos.close();
} catch (IOException ex) {
if (getLog().isDebugEnabled()) {
getLog().debug("ignore", ex);
}
}
}
if (os != null) {
try {
os.close();
} catch (IOException ex) {
if (getLog().isDebugEnabled()) {
getLog().debug("ignore", ex);
}
}
}
} }
} }
} }