Skip to content

Commit de9058e

Browse files
authored
Avoid warning about labelAtomSet during Slave.readResolve (jenkinsci#10863)
2 parents 2a27e84 + e19186b commit de9058e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import edu.umd.cs.findbugs.annotations.CheckForNull;
2929
import edu.umd.cs.findbugs.annotations.NonNull;
30+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3031
import hudson.DescriptorExtensionList;
3132
import hudson.EnvVars;
3233
import hudson.FilePath;
@@ -102,6 +103,7 @@
102103
*
103104
* @author Kohsuke Kawaguchi
104105
*/
106+
@SuppressFBWarnings(value = "DESERIALIZATION_GADGET", justification = "unhappy about existence of readResolve?")
105107
public abstract class Slave extends Node implements Serializable {
106108

107109
private static final Logger LOGGER = Logger.getLogger(Slave.class.getName());
@@ -381,7 +383,9 @@ private void _setLabelString(String labelString) {
381383
@Override
382384
protected Set<LabelAtom> getLabelAtomSet() {
383385
if (labelAtomSet == null) {
384-
warnPlugin();
386+
if (!insideReadResolve.get()) {
387+
warnPlugin();
388+
}
385389
this.labelAtomSet = Collections.unmodifiableSet(Label.parse(label));
386390
}
387391
return labelAtomSet;
@@ -627,14 +631,21 @@ public int hashCode() {
627631
return name.hashCode();
628632
}
629633

634+
private static final ThreadLocal<Boolean> insideReadResolve = ThreadLocal.withInitial(() -> false);
635+
630636
/**
631637
* Invoked by XStream when this object is read into memory.
632638
*/
633639
protected Object readResolve() {
634640
if (nodeProperties == null)
635641
nodeProperties = new DescribableList<>(this);
636642
previouslyAssignedLabels = new HashSet<>();
637-
_setLabelString(label);
643+
insideReadResolve.set(true);
644+
try {
645+
_setLabelString(label);
646+
} finally {
647+
insideReadResolve.set(false);
648+
}
638649
return this;
639650
}
640651

0 commit comments

Comments
 (0)