Russole commented on code in PR #23436:
URL: https://github.com/apache/kafka/pull/23436#discussion_r3998354289
##########
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()) {
+ throw new NumberFormatException(about + ": expected an integer
type, but got " +
+ node.getNodeType());
}
+ return node.intValue();
}
public static long jsonNodeToLong(JsonNode node, String about) {
- if (node.isLong()) {
- return node.asLong();
- }
- 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 Long.parseLong(text.substring(2), 16);
- } catch (NumberFormatException e) {
- throw new NumberFormatException(about + ": failed to " +
- "parse hexadecimal number: " + e.getMessage());
- }
- } else {
- try {
- return Long.parseLong(text);
- } catch (NumberFormatException e) {
- throw new NumberFormatException(about + ": failed to " +
- "parse number: " + e.getMessage());
- }
+ if (!node.isIntegralNumber() || !node.canConvertToLong()) {
Review Comment:
You're right. It was a fallback for other integral node types. I'll update
the description.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]