Fix BigDecimalTest.test_stripTrailingZero.
jessewilson reverted an upstream change (https://issues.apache.org/jira/browse/HARMONY-4623)
that caused an RI incompatibility. Although it seems like the RI behavior is
wrong, the poor design of BigDecimal.equals (which checks both value *and*
scale) probably means we should remain compatible.
This patch changes the test expectation to match the RI's behavior and adds
a comment in both the code and its test explaining that this is deliberate.
diff --git a/libcore/math/src/main/java/java/math/BigDecimal.java b/libcore/math/src/main/java/java/math/BigDecimal.java
index 33042ba..4e4875b 100644
--- a/libcore/math/src/main/java/java/math/BigDecimal.java
+++ b/libcore/math/src/main/java/java/math/BigDecimal.java
@@ -2148,7 +2148,10 @@
long newScale = scale;
if (isZero()) {
+ // BEGIN android-changed: preserve RI compatibility, so BigDecimal.equals (which checks
+ // value *and* scale) continues to work.
return this;
+ // END android-changed
}
BigInteger strippedBI = getUnscaledValue();
BigInteger[] quotAndRem;
diff --git a/libcore/math/src/test/java/tests/api/java/math/BigDecimalTest.java b/libcore/math/src/test/java/tests/api/java/math/BigDecimalTest.java
index 572f2c1..29d68a2 100644
--- a/libcore/math/src/test/java/tests/api/java/math/BigDecimalTest.java
+++ b/libcore/math/src/test/java/tests/api/java/math/BigDecimalTest.java
@@ -1293,7 +1293,6 @@
method = "stripTrailingZeros",
args = {}
)
- @AndroidOnly("Stripping trailing zeroes from 0.000 value doesn't work on RI. See below")
public void test_stripTrailingZero() {
BigDecimal sixhundredtest = new BigDecimal("600.0");
assertTrue("stripTrailingZero failed for 600.0",
@@ -1306,11 +1305,13 @@
((notrailingzerotest.stripTrailingZeros()).scale() == 0)
);
+ // BEGIN android-changed: preserve RI compatibility, so BigDecimal.equals (which checks
+ // value *and* scale) continues to work. https://issues.apache.org/jira/browse/HARMONY-4623
/* Zero */
- //regression for HARMONY-4623, NON-BUG DIFF with RI
BigDecimal zerotest = new BigDecimal("0.0000");
assertEquals("stripTrailingZero failed for 0.0000",
- 0, (zerotest.stripTrailingZeros()).scale() );
+ 4, (zerotest.stripTrailingZeros()).scale() );
+ // END android-changed
}
@TestTargetNew(