Skip to content

Commit e1a96cf

Browse files
committed
JENKINS-75299 Jenkins not starting due to NPE
1 parent d220b37 commit e1a96cf

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/main/java/org/jenkinsci/plugins/scriptler/config/ScriptSet.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
public class ScriptSet {
3535
// have it sorted
36-
protected final Set<Script> scriptSet = new TreeSet<>();
36+
protected Set<Script> scriptSet = new TreeSet<>();
3737

3838
public Script getScriptById(String id) {
3939
for (Script scr : scriptSet) {
@@ -89,6 +89,9 @@ private Script merge(Script origin, Script newScript) {
8989
}
9090

9191
public final Set<Script> getScripts() {
92+
if (scriptSet == null) {
93+
scriptSet = new TreeSet<>();
94+
}
9295
return Collections.unmodifiableSet(scriptSet);
9396
}
9497

@@ -103,6 +106,9 @@ public final Set<Script> getUserScripts() {
103106
}
104107

105108
public void setScripts(Set<Script> scripts) {
109+
if (scriptSet == null) {
110+
scriptSet = new TreeSet<>();
111+
}
106112
scriptSet.clear();
107113
scriptSet.addAll(scripts);
108114
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.jenkinsci.plugins.scriptler.config;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertNotNull;
5+
6+
import java.util.Collections;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class ScriptSetTest {
10+
11+
@Test
12+
public void testGetScriptsHandlesNull() {
13+
ScriptSet scriptSet = new ScriptSet();
14+
15+
scriptSet.scriptSet = null;
16+
17+
assertNotNull(scriptSet.getScripts(), "getScripts() should never return null");
18+
assertEquals(
19+
Collections.emptySet(), scriptSet.getScripts(), "Should return empty set when internal state is null");
20+
}
21+
22+
@Test
23+
public void testSetScriptsHandlesNull() {
24+
ScriptSet scriptSet = new ScriptSet();
25+
scriptSet.scriptSet = null;
26+
27+
scriptSet.setScripts(Collections.emptySet());
28+
29+
assertNotNull(scriptSet.getScripts(), "Internal set should be initialized after setter");
30+
}
31+
}

0 commit comments

Comments
 (0)