Skip to content
Permalink
Browse files

Merge pull request #35 from jenkinsci/JENKINS-43341

[JENKINS-43341] Protect code against NullPointerException
  • Loading branch information...
cyrille-leclerc committed Apr 10, 2017
2 parents 68fb1d3 + b128845 commit 01e8690c5db3e7130adf179e4bb05aa85917bf31
@@ -58,16 +58,6 @@

private static final Logger LOGGER = Logger.getLogger(MavenSpyLogProcessor.class.getName());

protected final transient DocumentBuilder documentBuilder;

public MavenSpyLogProcessor() {
try {
documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new IllegalStateException(e);
}
}

public void processMavenSpyLogs(StepContext context, FilePath mavenSpyLogFolder) throws IOException, InterruptedException {
FilePath[] mavenSpyLogsList = mavenSpyLogFolder.list("maven-spy-*.log");
LOGGER.log(Level.FINE, "Found {0} maven execution reports in {1}", new Object[]{mavenSpyLogsList.length, mavenSpyLogFolder});
@@ -79,10 +69,20 @@ public void processMavenSpyLogs(StepContext context, FilePath mavenSpyLogFolder)
}
FilePath workspace = context.get(FilePath.class); // TODO check that it's the good workspace

DocumentBuilder documentBuilder;
try {
documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new IllegalStateException("Failure to create a DocumentBuilder", e);
}

for (FilePath mavenSpyLogs : mavenSpyLogsList) {
try {
LOGGER.log(Level.INFO, "Evaluate Maven Spy logs: " + mavenSpyLogs.getRemote());
InputStream mavenSpyLogsInputStream = mavenSpyLogs.read();
if (mavenSpyLogsInputStream == null) {
throw new IllegalStateException("InputStream for " + mavenSpyLogs.getRemote() + " is null");
}

Element mavenSpyLogsElt = documentBuilder.parse(mavenSpyLogsInputStream).getDocumentElement();

0 comments on commit 01e8690

Please sign in to comment.
You can’t perform that action at this time.