Skip to content

Commit

Permalink
[JENKINS-43341] Protect code against NullPointerException and throw I…
Browse files Browse the repository at this point in the history
…llegalStateException in case of uncertain code path
  • Loading branch information
Cyrille Le Clerc committed Apr 8, 2017
1 parent c03c606 commit b128845
Showing 1 changed file with 10 additions and 10 deletions.
Expand Up @@ -58,16 +58,6 @@ public class MavenSpyLogProcessor implements Serializable {

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

Expand Down

0 comments on commit b128845

Please sign in to comment.