hickey-ai opened a new issue, #16521:
URL: https://github.com/apache/dubbo/issues/16521

   ### Pre-check
   
   - [x] I am sure that all the content I provide is in English.
   
   
   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/dubbo/issues?q=is%3Aissue) and found no 
similar issues.
   
   
   ### Apache Dubbo Component
   
   Java SDK (apache/dubbo)
   
   ### Dubbo Version
   
   Apache Dubbo 3.3.7-SNAPSHOT, branch 3.3 at 
b73b9d131b31ed43869778abbbe799b8cd0d1d1b; OpenJDK 21; Windows. The actual 
dubbo-common module was built and tested (release 8 compiler target). Released 
artifacts and full-repository or production-network behavior were not 
separately tested.
   
   ### Steps to reproduce this issue
   
   Reproduce against the unmodified source above with JUnit 5:
   
   ```java
   import java.math.BigDecimal;
   import java.math.BigInteger;
   import org.apache.dubbo.common.utils.CompatibleTypeUtils;
   import org.apache.dubbo.common.utils.PojoUtils;
   import org.junit.jupiter.api.Test;
   import static org.junit.jupiter.api.Assertions.assertEquals;
   
   class DecimalConversionRegression {
       @Test
       void integralValueMustNotWrapThroughLong() {
           BigDecimal value = new BigDecimal("9223372036854775808.75");
           BigInteger expected = new BigInteger("9223372036854775808");
           assertEquals(expected,
                   CompatibleTypeUtils.compatibleTypeConvert(value, 
BigInteger.class));
           assertEquals(expected, PojoUtils.realize(value, BigInteger.class));
       }
   }
   ```
   
   Both conversion entry points return -9223372036854775808 instead. The 
BigInteger branch currently constructs BigInteger.valueOf(number.longValue()), 
so narrowing to signed 64 bits happens before construction. Large negative 
values and larger positive/negative decimals reproduce the same loss.
   
   ### What you expected to happen
   
   Preserve the complete arbitrary-precision integral part when converting 
BigDecimal to BigInteger. Fractional values should continue truncating toward 
zero, matching BigDecimal.toBigInteger(). Existing Integer/Long conversion 
behavior and the existing BigInteger identity path should remain compatible.
   
   ### Anything else
   
   The public PojoUtils.realize entry point reproduces the corruption. The 
compatibility response filter also delegates to these helpers; this report does 
not assume a particular deployment or serializer returns this shape.
   
   Seven decimal cases cover the two long bounds, large positive/negative 
fractional values and small-fraction controls; additional tests cover the POJO 
entry point, legacy integral conversions and identity preservation. Five 
regression invocations fail before the fix. All 54 CompatibleTypeUtilsTest / 
PojoUtilsTest invocations pass after the targeted BigDecimal.toBigInteger 
change, along with lifecycle Spotless and git diff --check.
   
   Searched existing issues and PRs for CompatibleTypeUtils, 
compatibleTypeConvert, BigInteger and BigDecimal precision; no matching fix was 
found. The tested proposed patch and regression tests are on hickey-ai/dubbo 
branch codex/fix-bigdecimal-biginteger-value; I will link the corresponding PR. 
This is a numeric correctness report, not a security or measured 
production-impact claim. Investigation and patch preparation were AI-assisted; 
the reported tests were executed locally.
   
   ### Do you have a (mini) reproduction demo?
   
   - [x] Yes, I have a minimal reproduction demo to help resolve this issue 
more effectively!
   
   ### Are you willing to submit a pull request to fix on your own?
   
   - [x] Yes I am willing to submit a pull request on my own!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to