Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4334315

DecimalFormat.clone() does not clone digitList attribute

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 1.1.7
    • core-libs
    • x86
    • windows_nt



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

            okutsu Masayoshi Okutsu
            skondamasunw Suresh Kondamareddy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: