36
36
import hudson .Util ;
37
37
import hudson .cli .CLI ;
38
38
import hudson .model .Descriptor .FormException ;
39
+ import hudson .model .labels .LabelAtom ;
39
40
import hudson .remoting .Callable ;
40
41
import hudson .remoting .Channel ;
41
42
import hudson .remoting .Which ;
60
61
import java .net .URLConnection ;
61
62
import java .util .ArrayList ;
62
63
import java .util .Collection ;
64
+ import java .util .Collections ;
63
65
import java .util .List ;
64
66
import java .util .Set ;
65
67
import java .util .jar .JarFile ;
@@ -179,6 +181,7 @@ protected Slave(@NonNull String name, String remoteFS, ComputerLauncher launcher
179
181
this .name = name ;
180
182
this .remoteFS = remoteFS ;
181
183
this .launcher = launcher ;
184
+ this .labelAtomSet = Collections .unmodifiableSet (Label .parse (label ));
182
185
}
183
186
184
187
/**
@@ -193,7 +196,7 @@ protected Slave(@NonNull String name, String nodeDescription, String remoteFS, i
193
196
this .numExecutors = numExecutors ;
194
197
this .mode = mode ;
195
198
this .remoteFS = Util .fixNull (remoteFS ).trim ();
196
- this .label = Util . fixNull ( labelString ). trim ( );
199
+ this .labelAtomSet = Collections . unmodifiableSet ( Label . parse ( labelString ) );
197
200
this .launcher = launcher ;
198
201
this .retentionStrategy = retentionStrategy ;
199
202
getAssignedLabels (); // compute labels now
@@ -308,6 +311,10 @@ public DescribableList<NodeProperty<?>, NodePropertyDescriptor> getNodePropertie
308
311
309
312
@ DataBoundSetter
310
313
public void setNodeProperties (List <? extends NodeProperty <?>> properties ) throws IOException {
314
+ if (nodeProperties == null ) {
315
+ warnPlugin ();
316
+ nodeProperties = new DescribableList <>(this );
317
+ }
311
318
nodeProperties .replaceBy (properties );
312
319
}
313
320
@@ -328,11 +335,33 @@ public String getLabelString() {
328
335
@ Override
329
336
@ DataBoundSetter
330
337
public void setLabelString (String labelString ) throws IOException {
331
- this . label = Util . fixNull (labelString ). trim ( );
338
+ _setLabelString (labelString );
332
339
// Compute labels now.
333
340
getAssignedLabels ();
334
341
}
335
342
343
+ private void _setLabelString (String labelString ) {
344
+ this .label = Util .fixNull (labelString ).trim ();
345
+ this .labelAtomSet = Collections .unmodifiableSet (Label .parse (label ));
346
+ }
347
+
348
+ @ CheckForNull // should be @NonNull, but we've seen plugins overriding readResolve() without calling super.
349
+ private transient Set <LabelAtom > labelAtomSet ;
350
+
351
+ @ Override
352
+ protected Set <LabelAtom > getLabelAtomSet () {
353
+ if (labelAtomSet == null ) {
354
+ warnPlugin ();
355
+ this .labelAtomSet = Collections .unmodifiableSet (Label .parse (label ));
356
+ }
357
+ return labelAtomSet ;
358
+ }
359
+
360
+ private void warnPlugin () {
361
+ LOGGER .log (Level .WARNING , () -> getClass ().getName () + " or one of its superclass overrides readResolve() without calling super implementation." +
362
+ "Please file an issue against the plugin implementing it: " + Jenkins .get ().getPluginManager ().whichPlugin (getClass ()));
363
+ }
364
+
336
365
@ Override
337
366
public Callable <ClockDifference , IOException > getClockDifferenceCallable () {
338
367
return new GetClockDifference1 ();
@@ -574,6 +603,7 @@ public int hashCode() {
574
603
protected Object readResolve () {
575
604
if (nodeProperties == null )
576
605
nodeProperties = new DescribableList <>(this );
606
+ _setLabelString (label );
577
607
return this ;
578
608
}
579
609
0 commit comments