All of lore.kernel.org
 help / color / mirror / Atom feed
* [meta-java] [PATCH v2 0/2] add patches to fix BigDecimal
@ 2019-11-06 18:41 Chris Laplante
  2019-11-06 18:41 ` [meta-java] [PATCH v2 1/2] classpath: add patch to fix BigDecimal.compareTo() Chris Laplante
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Chris Laplante @ 2019-11-06 18:41 UTC (permalink / raw)
  To: openembedded-devel

v2: split into two commits; add sign-offs; add description to commits



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [meta-java] [PATCH v2 1/2] classpath: add patch to fix BigDecimal.compareTo()
  2019-11-06 18:41 [meta-java] [PATCH v2 0/2] add patches to fix BigDecimal Chris Laplante
@ 2019-11-06 18:41 ` Chris Laplante
  2019-11-06 18:41 ` [meta-java] [PATCH v2 2/2] classpath: add patch to fix BigDecimal.stripTrailingZeros()'s handling of 0 Chris Laplante
  2019-11-15  9:43 ` [meta-java] [PATCH v2 0/2] add patches to fix BigDecimal Richard Leitner
  2 siblings, 0 replies; 4+ messages in thread
From: Chris Laplante @ 2019-11-06 18:41 UTC (permalink / raw)
  To: openembedded-devel

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

Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
---
 ...implementation-of-compareTo-in-BigDecimal.patch | 68 ++++++++++++++++++++++
 recipes-core/classpath/classpath-native_0.99.bb    | 11 ++--
 2 files changed, 74 insertions(+), 5 deletions(-)
 create mode 100644 recipes-core/classpath/classpath-0.99/0001-Fix-bad-implementation-of-compareTo-in-BigDecimal.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@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@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-native_0.99.bb b/recipes-core/classpath/classpath-native_0.99.bb
index a1e1e0f..93d67b2 100644
--- a/recipes-core/classpath/classpath-native_0.99.bb
+++ b/recipes-core/classpath/classpath-native_0.99.bb
@@ -5,11 +5,12 @@ 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 \
            "
 SRC_URI[md5sum] = "0ae1571249172acd82488724a3b8acb4"
 SRC_URI[sha256sum] = "f929297f8ae9b613a1a167e231566861893260651d913ad9b6c11933895fecc8"
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [meta-java] [PATCH v2 2/2] classpath: add patch to fix BigDecimal.stripTrailingZeros()'s handling of 0.
  2019-11-06 18:41 [meta-java] [PATCH v2 0/2] add patches to fix BigDecimal Chris Laplante
  2019-11-06 18:41 ` [meta-java] [PATCH v2 1/2] classpath: add patch to fix BigDecimal.compareTo() Chris Laplante
@ 2019-11-06 18:41 ` Chris Laplante
  2019-11-15  9:43 ` [meta-java] [PATCH v2 0/2] add patches to fix BigDecimal Richard Leitner
  2 siblings, 0 replies; 4+ messages in thread
From: Chris Laplante @ 2019-11-06 18:41 UTC (permalink / raw)
  To: openembedded-devel

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/

Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
---
 ...ecimal.stripTrailingZeros-s-handling-of-0.patch | 51 ++++++++++++++++++++++
 recipes-core/classpath/classpath-native_0.99.bb    |  1 +
 2 files changed, 52 insertions(+)
 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/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@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@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 93d67b2..daf7611 100644
--- a/recipes-core/classpath/classpath-native_0.99.bb
+++ b/recipes-core/classpath/classpath-native_0.99.bb
@@ -11,6 +11,7 @@ SRC_URI += " \
            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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [meta-java] [PATCH v2 0/2] add patches to fix BigDecimal
  2019-11-06 18:41 [meta-java] [PATCH v2 0/2] add patches to fix BigDecimal Chris Laplante
  2019-11-06 18:41 ` [meta-java] [PATCH v2 1/2] classpath: add patch to fix BigDecimal.compareTo() Chris Laplante
  2019-11-06 18:41 ` [meta-java] [PATCH v2 2/2] classpath: add patch to fix BigDecimal.stripTrailingZeros()'s handling of 0 Chris Laplante
@ 2019-11-15  9:43 ` Richard Leitner
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Leitner @ 2019-11-15  9:43 UTC (permalink / raw)
  To: Chris Laplante, openembedded-devel

Hi,
this is a note to let you know that I've just added this series to the
master-next branch of the meta-java repository at
     git://git.yoctoproject.org/meta-java

As soon as it has gone through some more testing it will likely be
merged to the master branch.

If you have any questions, please let me know.

regards;Richard.L

On 06/11/2019 19:41, Chris Laplante wrote:
> v2: split into two commits; add sign-offs; add description to commits
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-11-15  9:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-06 18:41 [meta-java] [PATCH v2 0/2] add patches to fix BigDecimal Chris Laplante
2019-11-06 18:41 ` [meta-java] [PATCH v2 1/2] classpath: add patch to fix BigDecimal.compareTo() Chris Laplante
2019-11-06 18:41 ` [meta-java] [PATCH v2 2/2] classpath: add patch to fix BigDecimal.stripTrailingZeros()'s handling of 0 Chris Laplante
2019-11-15  9:43 ` [meta-java] [PATCH v2 0/2] add patches to fix BigDecimal Richard Leitner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.