You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "chia7712 (via GitHub)" <gi...@apache.org> on 2026/09/13 14:52:05 UTC

Re: [PR] KAFKA-21058: Simplify jsonNodeToInt and jsonNodeToLong [kafka]

chia7712 commented on code in PR #23436:
URL: https://github.com/apache/kafka/pull/23436#discussion_r3999923563


##########
clients/src/main/java/org/apache/kafka/common/protocol/MessageUtil.java:
##########
@@ -111,55 +111,19 @@ public static long jsonNodeToUnsignedInt(JsonNode node, String about) {
     }
 
     public static int jsonNodeToInt(JsonNode node, String about) {
-        if (node.isInt()) {
-            return node.asInt();
-        }
-        if (node.isTextual()) {
-            throw new NumberFormatException(about + ": expected an integer or " +
-                "string type, but got " + node.getNodeType());
-        }
-        String text = node.asText();
-        if (text.startsWith("0x")) {
-            try {
-                return Integer.parseInt(text.substring(2), 16);
-            } catch (NumberFormatException e) {
-                throw new NumberFormatException(about + ": failed to " +
-                    "parse hexadecimal number: " + e.getMessage());
-            }
-        } else {
-            try {
-                return Integer.parseInt(text);
-            } catch (NumberFormatException e) {
-                throw new NumberFormatException(about + ": failed to " +
-                    "parse number: " + e.getMessage());
-            }
+        if (!node.isIntegralNumber() || !node.canConvertToInt()) {

Review Comment:
   It seems to me they should use different error messages, making the output more readable. WDYT?



-- 
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-unsubscribe@kafka.apache.org

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