Skip to content
This repository was archived by the owner on Jan 17, 2024. It is now read-only.

Commit d2d4098

Browse files
authored
Merge pull request #34 from raydouglass/backwards-compat-customconfigitem
[REVIEW] Make CustomConfigItem backwards compatible
2 parents bf34a3c + 09dcd1e commit d2d4098

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

src/main/java/com/gpuopenanalytics/jenkins/remotedocker/config/CustomConfigItem.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626

2727
import com.gpuopenanalytics.jenkins.remotedocker.AbstractDockerLauncher;
2828
import com.gpuopenanalytics.jenkins.remotedocker.Utils;
29+
import org.apache.commons.lang.StringUtils;
2930

30-
import java.io.IOException;
31-
import java.io.ObjectInputStream;
32-
import java.io.ObjectOutputStream;
3331
import java.util.Objects;
3432
import java.util.Optional;
3533

@@ -41,14 +39,15 @@ public abstract class CustomConfigItem extends ConfigItem {
4139
public static final String CUSTOM_VALUE_INDICATOR = "custom";
4240

4341
private String value;
44-
private Optional<String> customValue;
42+
private transient Optional<String> customValue;
43+
private String customVal;
4544

4645
public CustomConfigItem(String value, String customValue) {
4746
this.value = value;
48-
if (CUSTOM_VALUE_INDICATOR.equals(value)) {
49-
this.customValue = Optional.ofNullable(customValue);
47+
if (StringUtils.isEmpty(customValue)) {
48+
this.customVal = null;
5049
} else {
51-
this.customValue = Optional.empty();
50+
this.customVal = customValue;
5251
}
5352
}
5453

@@ -58,7 +57,7 @@ public CustomConfigItem(String value, String customValue) {
5857
* @return
5958
*/
6059
public boolean isCustom() {
61-
return customValue.isPresent();
60+
return CUSTOM_VALUE_INDICATOR.equals(value);
6261
}
6362

6463
/**
@@ -76,7 +75,7 @@ public boolean isDefault() {
7675
* @return
7776
*/
7877
public String getValue() {
79-
return customValue.orElse(value);
78+
return Optional.ofNullable(customVal).orElse(value);
8079
}
8180

8281
public String getResolvedValue(AbstractDockerLauncher launcher) {
@@ -101,17 +100,13 @@ public String getRawValue() {
101100
* Used to get the raw custom value. Prefer {@link #getValue()} over this.
102101
*/
103102
public Optional<String> getRawCustomValue() {
104-
return customValue;
103+
return Optional.ofNullable(customVal);
105104
}
106105

107-
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
108-
value = (String) ois.readObject();
109-
customValue = Optional.ofNullable((String) ois.readObject());
110-
}
111-
112-
private void writeObject(ObjectOutputStream oos) throws IOException {
113-
oos.writeObject(value);
114-
oos.writeObject(customValue.orElse(null));
106+
protected Object readResolve() {
107+
if (customValue != null) {
108+
customVal = customValue.orElse(null);
109+
}
110+
return this;
115111
}
116-
117112
}

0 commit comments

Comments
 (0)