Name: skT45625 Date: 04/28/2000
java version "1.1.7A"
The implementation of DecimalFormat.clone() is as follows.
public Object clone() {
try {
DecimalFormat other = (DecimalFormat) super.clone();
other.symbols = (DecimalFormatSymbols) symbols.clone();
return other;
} catch (Exception e) {
throw new InternalError();
}
};
As it does not explicitly create a copy of the digitList instance variable
declared as follows :
private transient DigitList digitList = new DigitList();
the default object clone mechanism will just set the reference to the same
instance of DigitList. This means that cloned instances of DecimalFormat and by
implication SimpleDateFormat are not thread-safe.
As single instances of the XXXXFormat classes are not designed to be thread
safe then at lease clones of them should be so that factory methods can
generate new instances in an efficient manner.
(Review ID: 104266)
======================================================================
- duplicates
-
JDK-4407042 SimpleDateFormat clone() decendents corrupt each other
-
- Resolved
-