Removed unnecessary OutputStream closing. Also the flush and reset are not necessary since the stream is being closed right away.

This commit is contained in:
Anthony Whitford
2015-10-11 19:09:03 -07:00
parent 38e61ebd8d
commit b5026a45f6

View File

@@ -918,20 +918,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",
@@ -954,24 +945,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);
}
}
}
} }
} }
} }