According to Effective Java Item 24 (Make defensive copies when needed) mutable objects pose a security risk, especially when passed as constructor arguments. One is encouraged to make defensive copies as necessary.
BigDecimal
is meant to be immutable, but it is not final. According to Effective Java Item 15 (Minimise mutability), a class cannot be immutable unless it is final or all of its constructors are non-extendable.
To make matters worse, BigDecimal
doesn't provide a copy constructor.
So, do BigDecimal
arguments pose a security risk? Should one go through the painful process of invoking new BigDecimal(untrusted.toString())
?