Skip to content

Commit ab878c3

Browse files
authored
Defending against past corrupt builds (#651)
1 parent 2a6bf20 commit ab878c3

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/main/java/hudson/tasks/test/TestResult.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
*/
2424
package hudson.tasks.test;
2525

26+
import hudson.model.Job;
2627
import hudson.model.Result;
2728
import hudson.model.Run;
2829
import hudson.tasks.junit.TestAction;
2930
import java.util.Collection;
3031
import java.util.Collections;
3132
import java.util.Map;
33+
import java.util.logging.Level;
34+
import java.util.logging.Logger;
3235

3336
/**
3437
* A class that represents a general concept of a test result, without any
@@ -38,6 +41,7 @@
3841
* @since 1.343
3942
*/
4043
public abstract class TestResult extends TestObject {
44+
private static final Logger LOGGER = Logger.getLogger(TestResult.class.getName());
4145

4246
/**
4347
* If the concept of a parent action is important to a subclass, then it should
@@ -136,17 +140,27 @@ public TestResult getPreviousResult() {
136140
if (b == null) {
137141
return null;
138142
}
143+
Job<?, ?> job = b.getParent();
139144
while (true) {
140145
b = b.getPreviousBuild();
141146
if (b == null) {
142147
return null;
143148
}
144-
AbstractTestResultAction r = b.getAction(getParentAction().getClass());
145-
if (r != null) {
146-
TestResult result = r.findCorrespondingResult(this.getId());
147-
if (result != null) {
148-
return result;
149+
try {
150+
AbstractTestResultAction r = b.getAction(getParentAction().getClass());
151+
if (r != null) {
152+
TestResult result = r.findCorrespondingResult(this.getId());
153+
if (result != null) {
154+
return result;
155+
}
149156
}
157+
} catch (RuntimeException e) {
158+
Run<?, ?> loggedBuild = b;
159+
LOGGER.log(
160+
Level.WARNING,
161+
e,
162+
() -> "Failed to load (corrupt?) build " + job.getFullName() + " #" + loggedBuild.getNumber()
163+
+ ", skipping");
150164
}
151165
}
152166
}

0 commit comments

Comments
 (0)