A DESCRIPTION OF THE REQUEST :
BigDecimal.movePointLeft(int n) does not check if it is called with a zero argument, and will unnecessarily create a copy of the receiver, instead of returning this.
JUSTIFICATION :
Programmers who want to avoid unnecessary object creation now have to add additional branching:
return (scale>0)? b.movePointLeft(scale):b;
after the fix, this becomes
return b.movePointLeft(scale);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
BigDecimal.movePointLeft(int n), when called with an argument of zero, should return the receiver.
ACTUAL -
BigDecimal.movePointLeft(int n), when called with an argument of zero, currently instantiates a copy of the receiver.
---------- BEGIN SOURCE ----------
@Test
public void createsNewInstance() {
BigDecimal receiver = new BigDecimal("123.45");
BigDecimal result = receiver.movePointLeft(0);
assertNotSame(receiver, result);
}
---------- END SOURCE ----------
BigDecimal.movePointLeft(int n) does not check if it is called with a zero argument, and will unnecessarily create a copy of the receiver, instead of returning this.
JUSTIFICATION :
Programmers who want to avoid unnecessary object creation now have to add additional branching:
return (scale>0)? b.movePointLeft(scale):b;
after the fix, this becomes
return b.movePointLeft(scale);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
BigDecimal.movePointLeft(int n), when called with an argument of zero, should return the receiver.
ACTUAL -
BigDecimal.movePointLeft(int n), when called with an argument of zero, currently instantiates a copy of the receiver.
---------- BEGIN SOURCE ----------
@Test
public void createsNewInstance() {
BigDecimal receiver = new BigDecimal("123.45");
BigDecimal result = receiver.movePointLeft(0);
assertNotSame(receiver, result);
}
---------- END SOURCE ----------
- relates to
-
JDK-8289260 BigDecimal movePointLeft() and movePointRight() do not follow their API spec
- Closed
- links to