core: normalize service config number values#12826
Conversation
|
|
6253f6e to
679fdae
Compare
|
I didn't notice this and raised #12827. There are a few more cases handled in it, for all Number types. |
Thanks for pointing that out. I had focused this PR on the I see #12827 takes a broader approach by also updating |
There was a problem hiding this comment.
Pull request overview
This PR updates ManagedChannelImplBuilder.defaultServiceConfig() validation to accept numeric values provided as any Number (e.g., Integer), normalizing them to Double to match the existing internal service-config representation and avoid IllegalArgumentException for integer-looking JSON inputs.
Changes:
- Accept
Numbervalues in default service config maps/lists and normalize them viadoubleValue(). - Update tests to validate that integer numeric values (including nested ones) are accepted and stored as
Double.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java | Accept Number for service config validation and normalize to Double for downstream parsing. |
| core/src/test/java/io/grpc/internal/ManagedChannelImplBuilderTest.java | Update/add tests ensuring integer numeric values are accepted and converted to Double. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Vinod Kumar <codingkiddo@gmail.com>
679fdae to
da797e1
Compare
|
Using Number.doubleValue() is what we want, but I guess we can't validate that we didn't lose precision in the process. That's probably why It'd be good for someone to address that the code snippet exists and mention why it was too onerous. |
Thanks, that makes sense. I noticed the existing My reason for proposing this change is that the workaround is easy to miss and somewhat onerous for callers: every caller using a common JSON parser has to recursively walk and mutate/copy the full service config tree before passing it to This PR keeps the same conversion behavior as the documented snippet and keeps the internal representation as |
Fixes #12815
This updates default service config validation to accept numeric values represented as
Number, not onlyDouble.Common JSON parsers may deserialize integer-looking JSON values such as
maxAttempts: 4andbackoffMultiplier: 2asInteger, which previously causeddefaultServiceConfig()to fail withIllegalArgumentException.The values are normalized to
Doublewhen copied into the validated service config, preserving the existing internal representation expected by the service config parsing code.Tests were updated to cover direct and nested integer numeric values.
Tested with:
Note on existing Javadoc workaround
ManagedChannelBuilder.defaultServiceConfig()currently documents JSON numbers asDoubleand provides a recursiveconvertNumbers()helper for parsers that produceIntegeror otherNumbervalues. This PR centralizes the sameNumber.doubleValue()normalization insidedefaultServiceConfig()so callers do not need to duplicate the recursive conversion for nested maps/lists before passing common JSON parser output to the builder.