summaryrefslogtreecommitdiffstats
path: root/recipes-core/classpath/classpath-0.99/0002-Fix-BigDecimal.stripTrailingZeros-s-handling-of-0.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-core/classpath/classpath-0.99/0002-Fix-BigDecimal.stripTrailingZeros-s-handling-of-0.patch')
-rw-r--r--recipes-core/classpath/classpath-0.99/0002-Fix-BigDecimal.stripTrailingZeros-s-handling-of-0.patch51
1 files changed, 51 insertions, 0 deletions
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 @@
1From 14fa6fc320eb84d0adb9ae00dd66ddb1caaae2a6 Mon Sep 17 00:00:00 2001
2From: Chris Laplante <chris.laplante@agilent.com>
3Date: Wed, 2 Oct 2019 21:46:01 -0400
4Subject: [PATCH 2/2] Fix BigDecimal.stripTrailingZeros()'s handling of 0.
5
6Previously, 'new BigDecimal("0").stripTrailingZeros()' would blow up:
7
8Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
9 at java.lang.String.charAt
10 at java.math.BigDecimal.stripTrailingZeros
11
12Fixes https://sourceforge.net/p/saxon/mailman/message/27204592/
13
14Upstream-Status: Inappropriate [dead project]
15
16Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
17---
18 java/math/BigDecimal.java | 7 ++++++-
19 1 file changed, 6 insertions(+), 1 deletion(-)
20
21diff --git a/java/math/BigDecimal.java b/java/math/BigDecimal.java
22index e14d894..5e30f1c 100644
23--- a/java/math/BigDecimal.java
24+++ b/java/math/BigDecimal.java
25@@ -1335,17 +1335,22 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>
26 */
27 public BigDecimal stripTrailingZeros()
28 {
29+ if (intVal.intValue() == 0)
30+ return ZERO;
31+
32 String intValStr = intVal.toString();
33 int newScale = scale;
34 int pointer = intValStr.length() - 1;
35+
36 // This loop adjusts pointer which will be used to give us the substring
37 // of intValStr to use in our new BigDecimal, and also accordingly
38 // adjusts the scale of our new BigDecimal.
39- while (intValStr.charAt(pointer) == '0')
40+ while (pointer >= 0 && intValStr.charAt(pointer) == '0')
41 {
42 pointer --;
43 newScale --;
44 }
45+
46 // Create a new BigDecimal with the appropriate substring and then
47 // set its scale.
48 BigDecimal result = new BigDecimal(intValStr.substring(0, pointer + 1));
49--
502.7.4
51