Skip to content

Commit

Permalink
[FIXED JENKINS-25800] Ensure BufferedReader in parseLog is closed
Browse files Browse the repository at this point in the history
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 Dec 18, 2014
1 parent 2f78ea5 commit 51e8a7a
Showing 1 changed file with 20 additions and 13 deletions.
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 51e8a7a

Please sign in to comment.