From 9a8f7ccba8771906bd74971f932ec608c94a21e0 Mon Sep 17 00:00:00 2001 From: Will Stranathan Date: Sat, 1 Feb 2014 09:33:47 -0500 Subject: [PATCH] Refactored the test run of GrokAssembly to avoid double-closing Former-commit-id: edc5ae7da2cb52900f9eed1cd133c843f161a9aa --- .../analyzer/AssemblyAnalyzer.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/AssemblyAnalyzer.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/AssemblyAnalyzer.java index 10ebef16a..c6de2ac9e 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/AssemblyAnalyzer.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/AssemblyAnalyzer.java @@ -168,32 +168,13 @@ public class AssemblyAnalyzer extends AbstractAnalyzer { while ((bread = is.read(buff)) >= 0) { fos.write(buff, 0, bread); } - fos.flush(); - fos.close(); - fos = null; grokAssemblyExe = tempFile; // Set the temp file to get deleted when we're done grokAssemblyExe.deleteOnExit(); LOG.log(Level.INFO, "Extracted GrokAssembly.exe to {0}", grokAssemblyExe.getPath()); - - // Now, need to see if GrokAssembly actually runs from this location. - final List args = buildArgumentList(); - try { - final Process p = new ProcessBuilder(args).start(); - final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(p.getInputStream()); - final XPath xpath = XPathFactory.newInstance().newXPath(); - final String error = xpath.evaluate("/assembly/error", doc); - if (p.exitValue() != 1 || error == null || "".equals(error)) { - LOG.warning("GrokAssembly.exe is not working properly"); - grokAssemblyExe = null; - throw new AnalysisException("Could not execute GrokAssembly"); - } - } catch (Exception e) { - LOG.warning("Could not execute GrokAssembly " + e.getMessage()); - throw new AnalysisException("Could not execute GrokAssembly", e); - } - - builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + } catch (IOException ioe) { + LOG.log(Level.WARNING, "Could not extract GrokAssembly.exe: {0}", ioe.getMessage()); + throw new AnalysisException("Could not extract GrokAssembly.exe", ioe); } finally { if (fos != null) { try { @@ -210,6 +191,25 @@ public class AssemblyAnalyzer extends AbstractAnalyzer { } } } + + // Now, need to see if GrokAssembly actually runs from this location. + final List args = buildArgumentList(); + try { + final Process p = new ProcessBuilder(args).start(); + final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(p.getInputStream()); + final XPath xpath = XPathFactory.newInstance().newXPath(); + final String error = xpath.evaluate("/assembly/error", doc); + if (p.exitValue() != 1 || error == null || "".equals(error)) { + LOG.warning("GrokAssembly.exe is not working properly"); + grokAssemblyExe = null; + throw new AnalysisException("Could not execute GrokAssembly"); + } + } catch (Exception e) { + LOG.warning("Could not execute GrokAssembly " + e.getMessage()); + throw new AnalysisException("Could not execute GrokAssembly", e); + } + + builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } @Override