Skip to content
Permalink
Browse files

[FIXED JENKINS-25800] Ensure BufferedReader in parseLog is closed

Added a try/finally block around the reader, so it doesn't leak resources. BufferedReader will automatically call close on the FileReader it wraps.
  • Loading branch information...
martinb3 committed Nov 26, 2014
1 parent 2f78ea5 commit 51e8a7a59c2bf69557891c2b7813c1f9973d5208
Showing with 20 additions and 13 deletions.
  1. +20 −13 src/main/java/com/chikli/hudson/plugin/naginator/NaginatorListener.java
@@ -43,10 +43,10 @@ public void onCompleted(AbstractBuild<?, ?> build, TaskListener listener) {
if ((!naginator.isRerunIfUnstable()) && (build.getResult() == Result.UNSTABLE)) {
return;
}

// Do nothing for a single Matrix run. (Run only when all Matrix finishes)
if (build instanceof MatrixRun) {
return;
return;
}

// If we're supposed to check for a regular expression in the build output before
@@ -78,12 +78,12 @@ public void onCompleted(AbstractBuild<?, ?> build, TaskListener listener) {
new Object[]{build.getNumber(), n, build.getProject().getName()} );

List<Combination> combsToRerun = new ArrayList<Combination>();

if (naginator.isRerunMatrixPart()) {
if (build instanceof MatrixBuild) {
MatrixBuild mb = (MatrixBuild) build;
List<MatrixRun> matrixRuns = mb.getRuns();

for(MatrixRun r : matrixRuns) {
if (r.getNumber() == build.getNumber()) {
if ((r.getResult() == SUCCESS) || (r.getResult() == ABORTED)) {
@@ -97,10 +97,10 @@ public void onCompleted(AbstractBuild<?, ?> build, TaskListener listener) {
combsToRerun.add(r.getParent().getCombination());
}
}

}
}

if (!combsToRerun.isEmpty()) {
LOGGER.log(Level.FINE, "schedule matrix rebuild");
scheduleMatrixBuild(build, combsToRerun, n);
@@ -152,14 +152,21 @@ private boolean parseLog(File logFile, String regexp) throws IOException {
// Assume default encoding and text files
String line;
Pattern pattern = Pattern.compile(regexp);
BufferedReader reader = new BufferedReader(new FileReader(logFile));
while ((line = reader.readLine()) != null) {
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
return true;
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(logFile));
while ((line = reader.readLine()) != null) {
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
return true;
}
}
return false;
}
finally {
if(reader != null)
reader.close();
}
return false;
}

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

0 comments on commit 51e8a7a

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