ezhou413 commented on code in PR #20134:
URL: https://github.com/apache/kafka/pull/20134#discussion_r2195915294


##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -1469,7 +1470,19 @@ public static <K, V> Map<K, V> filterMap(final Map<K, V> 
map, final Predicate<En
      * @return a map including all elements in properties
      */
     public static Map<String, Object> propsToMap(Properties properties) {
-        return castToStringObjectMap(properties);
+        try {
+            final Enumeration<?> enumeration = properties.propertyNames();
+            Map<String, Object> props = new HashMap<>();
+            while (enumeration.hasMoreElements()) {
+                Object key = enumeration.nextElement();
+                String keyString = (String) key;
+                Object value = (properties.get(keyString) != null) ? 
properties.get(keyString) : properties.getProperty(keyString);
+                props.put(keyString, value);
+            }
+            return props;
+        } catch (Exception e) {
+            throw new ConfigException("Key must be a string.");
+        }

Review Comment:
   Hi Kirk, I attempted to implement `propsToMap` in the way you suggested 
above, but if we pass in a `Properties` object with non-string keys, a 
`ClassCastException` is thrown by `properties.propertyNames()`. My 
implementation above is the workaround I found. 
   
   If it's assumed that all keys of the `Properties` object are `String`s, then 
I believe the code can be shortened, but might lead to some confusion during 
usage of `propsToMap`. 
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to