Skip to content

Commit d147200

Browse files
committed
Fix NPE in ReverseBuildTrigger due to null upstream threshold (JENKINS-39044)
1 parent 1366fa9 commit d147200

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

core/src/main/java/jenkins/triggers/ReverseBuildTrigger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private boolean shouldTrigger(Run upstreamBuild, TaskListener listener) {
166166
return false;
167167
}
168168
Result result = upstreamBuild.getResult();
169-
return result != null && result.isBetterOrEqualTo(threshold);
169+
return result != null && result.isBetterOrEqualTo(threshold != null ? threshold : Result.SUCCESS);
170170
}
171171

172172
@Override public void buildDependencyGraph(final AbstractProject downstream, DependencyGraph graph) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright 2012 Jesse Glick.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package hudson.model;
26+
27+
import static org.junit.jupiter.api.Assertions.assertFalse;
28+
import static org.junit.jupiter.api.Assertions.assertTrue;
29+
30+
import org.junit.jupiter.api.Test;
31+
32+
public class ResultTest {
33+
34+
@Test
35+
public void testIsBetterOrEqualToHandlesNull() {
36+
// This used to throw NPE [JENKINS-39044]
37+
// We assume nothing is "better or equal" to a null/undefined requirement
38+
assertFalse(Result.SUCCESS.isBetterOrEqualTo(null), "Comparing against null should not crash");
39+
}
40+
41+
@Test
42+
public void testIsBetterOrEqualToBasic() {
43+
// Verify standard logic still works
44+
assertTrue(Result.SUCCESS.isBetterOrEqualTo(Result.FAILURE));
45+
assertTrue(Result.SUCCESS.isBetterOrEqualTo(Result.SUCCESS));
46+
assertFalse(Result.FAILURE.isBetterOrEqualTo(Result.SUCCESS));
47+
}
48+
}

0 commit comments

Comments
 (0)