JDK-4334315 : DecimalFormat.clone() does not clone digitList attribute
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.1.7
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2000-04-28
  • Updated: 2001-02-07
  • Resolved: 2001-02-07
Related Reports
Duplicate :  
Description

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) 
======================================================================

Comments
WORK AROUND Name: skT45625 Date: 04/28/2000 None ======================================================================
11-06-2004

EVALUATION The same problem was reported as a SimpleDateFormat.clone problem by bug #4407042. It's being fixed. masayoshi.okutsu@Eng 2001-02-07
07-02-2001