Skip to content

Commit b7d6a94

Browse files
committed
Fix NPE in Result.fromString when string is null [JENKINS-39044]
1 parent 1366fa9 commit b7d6a94

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

core/src/main/java/hudson/model/Result.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ public boolean isBetterThan(@NonNull Result that) {
147147
return this.ordinal < that.ordinal;
148148
}
149149

150-
public boolean isBetterOrEqualTo(@NonNull Result that) {
150+
public boolean isBetterOrEqualTo(Result that) {
151+
if (that == null) return false;
151152
return this.ordinal <= that.ordinal;
152153
}
153154

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)