Skip to content

KAFKA-21058: Simplify jsonNodeToInt and jsonNodeToLong - #23436

Open
Russole wants to merge 2 commits into
apache:trunkfrom
Russole:KAFKA-21058-Remove-the-dead-code-from-jsonNodeToInt-and-jsonNodeToLong
Open

Russole wants to merge 2 commits into
apache:trunkfrom
Russole:KAFKA-21058-Remove-the-dead-code-from-jsonNodeToInt-and-jsonNodeToLong

Conversation

@Russole

@Russole Russole commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

This PR simplifies MessageUtil.jsonNodeToInt and jsonNodeToLong. The
existing code converts compatible numeric nodes to strings and parses
them back as a fallback. The new implementation keeps this behavior by
validating the integral value and its range before returning
intValue() or longValue() directly. Tests cover supported integral
nodes, out-of-range values, and invalid node types.

Testing

./gradlew clients:test --tests org.apache.kafka.common.protocol.MessageUtilTest

Reviewers: Chia-Ping Tsai chia7712@gmail.com

@github-actions github-actions Bot added triage PRs from the community clients small Small PRs labels Sep 11, 2026
throw new NumberFormatException(about + ": failed to " +
"parse number: " + e.getMessage());
}
if (!node.isIntegralNumber() || !node.canConvertToLong()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. It was not dead code. Rather, it is a kind of fallback for parsing "long" type. @Russole Would you mind updating the PR description?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. It was a fallback for other integral node types. I'll update the description.

@Russole Russole changed the title KAFKA-21058:Remove the dead code from jsonNodeToInt and jsonNodeToLong KAFKA-21058:Simplify jsonNodeToInt and jsonNodeToLong Sep 13, 2026
@Russole Russole changed the title KAFKA-21058:Simplify jsonNodeToInt and jsonNodeToLong KAFKA-21058: Simplify jsonNodeToInt and jsonNodeToLong Sep 13, 2026
@github-actions github-actions Bot removed the triage PRs from the community label Sep 13, 2026
throw new NumberFormatException(about + ": failed to " +
"parse number: " + e.getMessage());
}
if (!node.isIntegralNumber() || !node.canConvertToInt()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I’ve updated them to use separate messages for invalid types and out-of-range values.

@github-actions github-actions Bot removed the small Small PRs label Sep 13, 2026
@Russole
Russole requested a review from chia7712 September 13, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants