Skip to content

Commit 0b549b7

Browse files
authored
Enforce string values in InstanceSpec's custom properties (#1274)
`InstanceSpec`'s `customProperties` will be fed to `Properties` in `QuorumConfigBuilder::buildConfigProperties`, so we have to make sure it contains only string values. Instead of `ClassCastException` in read phase, this pr complains in `InstanceSpec` construction phase. We could deprecate these constructors in next step by introducing builder for `InstanceSpec`(#1222). Fixes #1178, CURATOR-663.
1 parent 2829144 commit 0b549b7

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,21 @@ public InstanceSpec(
209209
this.tickTime = (tickTime > 0 ? tickTime : -1); // -1 to set default value
210210
this.maxClientCnxns = (maxClientCnxns >= 0 ? maxClientCnxns : -1); // -1 to set default value
211211
this.customProperties = customProperties != null
212-
? Collections.<String, Object>unmodifiableMap(customProperties)
213-
: Collections.<String, Object>emptyMap();
212+
? Collections.unmodifiableMap(enforceStringMap(customProperties))
213+
: Collections.emptyMap();
214214
this.hostname = hostname == null ? localhost : hostname;
215215
}
216216

217+
private static Map<String, Object> enforceStringMap(Map<String, Object> properties) {
218+
for (Map.Entry<String, Object> entry : properties.entrySet()) {
219+
if (!(entry.getValue() instanceof String)) {
220+
String msg = String.format("property %s has non string value %s", entry.getKey(), entry.getValue());
221+
throw new IllegalArgumentException(msg);
222+
}
223+
}
224+
return properties;
225+
}
226+
217227
public int getServerId() {
218228
return serverId;
219229
}

0 commit comments

Comments
 (0)