[oe] [meta-java][PATCH] classpath-native: add patches to fix BigDecimal.compareTo() and BigDecimal.stripTrailingZeros()

Chris Laplante chris.laplante at agilent.com
Thu Oct 3 02:27:49 UTC 2019


---
 ...implementation-of-compareTo-in-BigDecimal.patch | 68 ++++++++++++++++++++++
 ...ecimal.stripTrailingZeros-s-handling-of-0.patch | 51 ++++++++++++++++
 recipes-core/classpath/classpath-native_0.99.bb    | 12 ++--
 3 files changed, 126 insertions(+), 5 deletions(-)
 create mode 100644 recipes-core/classpath/classpath-0.99/0001-Fix-bad-implementation-of-compareTo-in-BigDecimal.patch
 create mode 100644 recipes-core/classpath/classpath-0.99/0002-Fix-BigDecimal.stripTrailingZeros-s-handling-of-0.patch

diff --git a/recipes-core/classpath/classpath-0.99/0001-Fix-bad-implementation-of-compareTo-in-BigDecimal.patch b/recipes-core/classpath/classpath-0.99/0001-Fix-bad-implementation-of-compareTo-in-BigDecimal.patch
new file mode 100644
index 0000000..35fb81e
--- /dev/null
+++ b/recipes-core/classpath/classpath-0.99/0001-Fix-bad-implementation-of-compareTo-in-BigDecimal.patch
@@ -0,0 +1,68 @@
+From b561cdb6f3fef251696216775c775f84369278cc Mon Sep 17 00:00:00 2001
+From: Chris Laplante <chris.laplante at agilent.com>
+Date: Wed, 2 Oct 2019 21:38:11 -0400
+Subject: [PATCH 1/2] Fix bad implementation of compareTo in BigDecimal
+
+Prior to this patch compareTo couldn't handle operands with negative
+scales. It passes the following unit test from JDK8:
+http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/test/java/math/BigDecimal/CompareToTests.java
+
+Upstream-Status: Inappropriate [dead project]
+
+Signed-off-by: Chris Laplante <chris.laplante at agilent.com>
+---
+ java/math/BigDecimal.java | 32 ++++++++++++++++++--------------
+ 1 file changed, 18 insertions(+), 14 deletions(-)
+
+diff --git a/java/math/BigDecimal.java b/java/math/BigDecimal.java
+index 7f4546c..e14d894 100644
+--- a/java/math/BigDecimal.java
++++ b/java/math/BigDecimal.java
+@@ -861,26 +861,30 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>
+     if (scale == val.scale)
+       return intVal.compareTo (val.intVal);
+ 
+-    BigInteger thisParts[] =
+-      intVal.divideAndRemainder (BigInteger.TEN.pow (scale));
+-    BigInteger valParts[] =
+-      val.intVal.divideAndRemainder (BigInteger.TEN.pow (val.scale));
++    BigInteger[] thisParts = new BigInteger[2];
++    BigInteger[] valParts = new BigInteger[2];
++
++    if (scale > 0)
++      thisParts = intVal.divideAndRemainder (BigInteger.TEN.pow (scale));
++    else
++      {
++        thisParts[0] = intVal.multiply (BigInteger.TEN.pow (-scale));
++        thisParts[1] = BigInteger.ZERO;
++      }
++
++    if (val.scale > 0)
++      valParts = val.intVal.divideAndRemainder (BigInteger.TEN.pow (val.scale));
++    else
++      {
++        valParts[0] = val.intVal.multiply (BigInteger.TEN.pow (-val.scale));
++        valParts[1] = BigInteger.ZERO;
++      }
+ 
+     int compare;
+     if ((compare = thisParts[0].compareTo (valParts[0])) != 0)
+       return compare;
+ 
+     // quotients are the same, so compare remainders
+-
+-    // Add some trailing zeros to the remainder with the smallest scale
+-    if (scale < val.scale)
+-      thisParts[1] = thisParts[1].multiply
+-                        (BigInteger.valueOf (10).pow (val.scale - scale));
+-    else if (scale > val.scale)
+-      valParts[1] = valParts[1].multiply
+-                        (BigInteger.valueOf (10).pow (scale - val.scale));
+-
+-    // and compare them
+     return thisParts[1].compareTo (valParts[1]);
+   }
+ 
+-- 
+2.7.4
+
diff --git a/recipes-core/classpath/classpath-0.99/0002-Fix-BigDecimal.stripTrailingZeros-s-handling-of-0.patch b/recipes-core/classpath/classpath-0.99/0002-Fix-BigDecimal.stripTrailingZeros-s-handling-of-0.patch
new file mode 100644
index 0000000..645b010
--- /dev/null
+++ b/recipes-core/classpath/classpath-0.99/0002-Fix-BigDecimal.stripTrailingZeros-s-handling-of-0.patch
@@ -0,0 +1,51 @@
+From 14fa6fc320eb84d0adb9ae00dd66ddb1caaae2a6 Mon Sep 17 00:00:00 2001
+From: Chris Laplante <chris.laplante at agilent.com>
+Date: Wed, 2 Oct 2019 21:46:01 -0400
+Subject: [PATCH 2/2] Fix BigDecimal.stripTrailingZeros()'s handling of 0.
+
+Previously, 'new BigDecimal("0").stripTrailingZeros()' would blow up:
+
+Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
+   at java.lang.String.charAt
+   at java.math.BigDecimal.stripTrailingZeros
+
+Fixes https://sourceforge.net/p/saxon/mailman/message/27204592/
+
+Upstream-Status: Inappropriate [dead project]
+
+Signed-off-by: Chris Laplante <chris.laplante at agilent.com>
+---
+ java/math/BigDecimal.java | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/java/math/BigDecimal.java b/java/math/BigDecimal.java
+index e14d894..5e30f1c 100644
+--- a/java/math/BigDecimal.java
++++ b/java/math/BigDecimal.java
+@@ -1335,17 +1335,22 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>
+    */
+   public BigDecimal stripTrailingZeros()
+   {
++    if (intVal.intValue() == 0)
++      return ZERO;
++
+     String intValStr = intVal.toString();
+     int newScale = scale;
+     int pointer = intValStr.length() - 1;
++
+     // This loop adjusts pointer which will be used to give us the substring
+     // of intValStr to use in our new BigDecimal, and also accordingly
+     // adjusts the scale of our new BigDecimal.
+-    while (intValStr.charAt(pointer) == '0')
++    while (pointer >= 0 && intValStr.charAt(pointer) == '0')
+       {
+         pointer --;
+         newScale --;
+       }
++
+     // Create a new BigDecimal with the appropriate substring and then
+     // set its scale.
+     BigDecimal result = new BigDecimal(intValStr.substring(0, pointer + 1));
+-- 
+2.7.4
+
diff --git a/recipes-core/classpath/classpath-native_0.99.bb b/recipes-core/classpath/classpath-native_0.99.bb
index a1e1e0f..daf7611 100644
--- a/recipes-core/classpath/classpath-native_0.99.bb
+++ b/recipes-core/classpath/classpath-native_0.99.bb
@@ -5,11 +5,13 @@ DEPENDS += "classpath-initial-native ecj-initial-native virtual/java-initial-nat
 PR = "${INC_PR}.0"
 
 SRC_URI += " \
-            file://sun-security-getproperty.patch;striplevel=0 \
-            file://ecj_java_dir.patch \
-            file://autotools.patch \
-            file://miscompilation.patch \
-            file://toolwrapper-exithook.patch \
+           file://sun-security-getproperty.patch;striplevel=0 \
+           file://ecj_java_dir.patch \
+           file://autotools.patch \
+           file://miscompilation.patch \
+           file://toolwrapper-exithook.patch \
+           file://0001-Fix-bad-implementation-of-compareTo-in-BigDecimal.patch \
+           file://0002-Fix-BigDecimal.stripTrailingZeros-s-handling-of-0.patch \
            "
 SRC_URI[md5sum] = "0ae1571249172acd82488724a3b8acb4"
 SRC_URI[sha256sum] = "f929297f8ae9b613a1a167e231566861893260651d913ad9b6c11933895fecc8"
-- 
2.7.4



More information about the Openembedded-devel mailing list