You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by ea...@apache.org on 2026/10/20 02:41:09 UTC
(dubbo) branch 3.3 updated: Preserve BigDecimal integral value in BigInteger compatibility conversion (#16524)
This is an automated email from the ASF dual-hosted git repository.
EarthChen pushed a commit to branch 3.3
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.3 by this push:
new cb05763298 Preserve BigDecimal integral value in BigInteger compatibility conversion (#16524)
cb05763298 is described below
commit cb05763298f081ed17171d704408b6478cf8fd83
Author: hickey-ai <31...@qq.com>
AuthorDate: Tue Oct 20 10:41:02 2026 +0800
Preserve BigDecimal integral value in BigInteger compatibility conversion (#16524)
* Preserve BigDecimal integral value in BigInteger conversion
* Test arbitrary-precision numeric and POJO conversions
---
.../dubbo/common/utils/CompatibleTypeUtils.java | 4 ++-
.../common/utils/CompatibleTypeUtilsTest.java | 35 ++++++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CompatibleTypeUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CompatibleTypeUtils.java
index 3eb4e1860a..43ab5710e0 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CompatibleTypeUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CompatibleTypeUtils.java
@@ -184,7 +184,9 @@ public class CompatibleTypeUtils {
return number.doubleValue();
}
if (type == BigInteger.class) {
- return BigInteger.valueOf(number.longValue());
+ return number instanceof BigDecimal
+ ? ((BigDecimal) number).toBigInteger()
+ : BigInteger.valueOf(number.longValue());
}
if (type == BigDecimal.class) {
return new BigDecimal(number.toString());
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CompatibleTypeUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CompatibleTypeUtilsTest.java
index cf1c4436c0..5416b83ba5 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CompatibleTypeUtilsTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CompatibleTypeUtilsTest.java
@@ -28,6 +28,8 @@ import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -36,6 +38,39 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class CompatibleTypeUtilsTest {
+ @ParameterizedTest
+ @CsvSource({
+ "9223372036854775808, 9223372036854775808",
+ "-9223372036854775809, -9223372036854775809",
+ "123456789012345678901234567890.987, 123456789012345678901234567890",
+ "-123456789012345678901234567890.987, -123456789012345678901234567890",
+ "1.9, 1",
+ "-1.9, -1",
+ "0.9, 0"
+ })
+ void testBigDecimalToBigIntegerPreservesIntegralValue(String decimal, String integer) {
+ assertEquals(
+ new BigInteger(integer),
+ CompatibleTypeUtils.compatibleTypeConvert(new BigDecimal(decimal), BigInteger.class));
+ }
+
+ @Test
+ void testBigDecimalToBigIntegerThroughPojoRealization() {
+ assertEquals(
+ new BigInteger("9223372036854775808"),
+ PojoUtils.realize(new BigDecimal("9223372036854775808.75"), BigInteger.class));
+ }
+
+ @Test
+ void testIntegralConversionsToBigIntegerStayCompatible() {
+ assertEquals(BigInteger.valueOf(42), CompatibleTypeUtils.compatibleTypeConvert(42, BigInteger.class));
+ assertEquals(
+ BigInteger.valueOf(Long.MIN_VALUE),
+ CompatibleTypeUtils.compatibleTypeConvert(Long.MIN_VALUE, BigInteger.class));
+ BigInteger integer = new BigInteger("123456789012345678901234567890");
+ assertSame(integer, CompatibleTypeUtils.compatibleTypeConvert(integer, BigInteger.class));
+ }
+
@SuppressWarnings("unchecked")
@Test
void testCompatibleTypeConvert() throws Exception {