File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
main/java/org/jenkinsci/plugins/scriptler/config
test/java/org/jenkinsci/plugins/scriptler/config Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 3333 */
3434public 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 }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments