Skip to content

core: support Integer and Long in service configuration parsing#12827

Open
kannanjgithub wants to merge 2 commits into
grpc:masterfrom
kannanjgithub:service-config-parser-integer
Open

core: support Integer and Long in service configuration parsing#12827
kannanjgithub wants to merge 2 commits into
grpc:masterfrom
kannanjgithub:service-config-parser-integer

Conversation

@kannanjgithub
Copy link
Copy Markdown
Contributor

@kannanjgithub kannanjgithub commented May 25, 2026

Previously, ManagedChannelImplBuilder and JsonUtil only supported Double or String for numeric values in service configurations. This caused IllegalArgumentException when using service configurations produced by JSON parsers like Jackson that represent non-decimal numbers as Integer or Long.

This change:

  • Updates ManagedChannelImplBuilder to accept any Number type.
  • Enhances JsonUtil to robustly handle numeric conversions while maintaining necessary integral checks.

Fixes #12815

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to make gRPC-Java’s service config handling tolerant of numeric values represented as Integer/Long (common with JSON parsers like Jackson), instead of requiring Double everywhere.

Changes:

  • Allow ManagedChannelImplBuilder.defaultServiceConfig() to accept Number values (not just Double).
  • Update JsonUtil numeric accessors to accept Number and convert appropriately.
  • Expand ManagedChannelImplBuilderTest to cover integer/long numeric values in service configs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
core/src/test/java/io/grpc/internal/ManagedChannelImplBuilderTest.java Adds tests asserting defaultServiceConfig() accepts Integer/Long (including in lists).
core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java Broadens accepted numeric types in service config maps/lists from Double to Number.
core/src/main/java/io/grpc/internal/JsonUtil.java Accepts Number for numeric getters and performs conversions/integrality validation.
Comments suppressed due to low confidence (1)

core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java:589

  • ManagedChannelImplBuilder now accepts any Number in service configs, but some downstream parsing still assumes numeric values are Double (e.g., ServiceConfigUtil#getStatusCodesFromList checks status instanceof Double). This means configs produced by Jackson that use Integer/Long can still fail later during service config parsing (not just at defaultServiceConfig() time). Consider updating the remaining instanceof Double service-config parsing sites to accept Number, or narrowing the accepted numeric types here to match what the parsers support.
        parsedMap.put(key, checkListEntryTypes((List<?>) value));
      } else if (value instanceof String) {
        parsedMap.put(key, value);
      } else if (value instanceof Number) {
        parsedMap.put(key, value);
      } else if (value instanceof Boolean) {
        parsedMap.put(key, value);
      } else {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +194 to 200
if (value instanceof Number) {
Number n = (Number) value;
double d = n.doubleValue();
long l = n.longValue();
if (l != d) {
throw new ClassCastException("Number expected to be long: " + d);
throw new ClassCastException("Number expected to be long: " + n);
}
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.

Done.

Comment thread core/src/main/java/io/grpc/internal/JsonUtil.java
Previously, ManagedChannelImplBuilder and JsonUtil only supported Double
or String for numeric values in service configurations. This caused
IllegalArgumentException when using service configurations produced by
JSON parsers like Jackson that represent non-decimal numbers as
Integer or Long.

This change:
 - Updates ManagedChannelImplBuilder to accept any Number type.
 - Enhances JsonUtil to robustly handle numeric conversions while
   maintaining necessary integral checks.
 - Adds ServiceConfigNumericTypeTest to verify support for Integer,
   Double, and Long types.

Fixes grpc#12815
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread core/src/test/java/io/grpc/internal/JsonUtilTest.java Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@kannanjgithub kannanjgithub requested a review from AgraVator May 26, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Service Configuration containing Integer values abort with IllegalArgumentException

2 participants