This is an automated email from the ASF dual-hosted git repository.

kezhuw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/curator.git


The following commit(s) were added to refs/heads/master by this push:
     new 0b549b7ef Enforce string values in InstanceSpec's custom properties 
(#1274)
0b549b7ef is described below

commit 0b549b7ef4c56cf4a2f30393ab31a4d67c493327
Author: Kezhu Wang <[email protected]>
AuthorDate: Tue Aug 19 21:00:32 2025 +0800

    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.
---
 .../main/java/org/apache/curator/test/InstanceSpec.java    | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git 
a/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java 
b/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java
index a5beced5a..531f5af74 100644
--- a/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java
+++ b/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java
@@ -209,11 +209,21 @@ public class InstanceSpec {
         this.tickTime = (tickTime > 0 ? tickTime : -1); // -1 to set default 
value
         this.maxClientCnxns = (maxClientCnxns >= 0 ? maxClientCnxns : -1); // 
-1 to set default value
         this.customProperties = customProperties != null
-                ? Collections.<String, Object>unmodifiableMap(customProperties)
-                : Collections.<String, Object>emptyMap();
+                ? 
Collections.unmodifiableMap(enforceStringMap(customProperties))
+                : Collections.emptyMap();
         this.hostname = hostname == null ? localhost : hostname;
     }
 
+    private static Map<String, Object> enforceStringMap(Map<String, Object> 
properties) {
+        for (Map.Entry<String, Object> entry : properties.entrySet()) {
+            if (!(entry.getValue() instanceof String)) {
+                String msg = String.format("property %s has non string value 
%s", entry.getKey(), entry.getValue());
+                throw new IllegalArgumentException(msg);
+            }
+        }
+        return properties;
+    }
+
     public int getServerId() {
         return serverId;
     }

Reply via email to