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

java.text.DecimalFormat.DecimalFormat(String, DecimalFormatSymbols) works wrong

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1.6
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Backports

        Description



        Name: dfC67450 Date: 10/19/97



        The java.text.DecimalFormat.DecimalFormat(String pattern,
        DecimalFormatSymbols symbols) constructor should clone second parameter
        using setDecimalFormatSymbols() method not just store the reference.
        (see Javadoc for DecimalFormat.setDecimalFormatSymbols() method:

             Sets the decimal format symbols, which is generally not changed
             by the programmer or user.
        )
           
         
        Here is the test demonstrating the bug:

        -----------------Test.java------------------------
        import java.text.*;

        public class Test {
            public static void main (String args[]){
                DecimalFormatSymbols symbols = new DecimalFormatSymbols();
                DecimalFormat df = new DecimalFormat("#,##0.0", symbols);
                long n = 123;
                System.out.println("format(" + n + ") = " +
                    df.format(n, new StringBuffer(), new FieldPosition(0)));
                symbols.setDecimalSeparator('p'); // change value of field
                System.out.println("format(" + n + ") = " +
                    df.format(n, new StringBuffer(), new FieldPosition(0)));

            }
        }
        ---------Output from the test---------------------
        format(123) = 123.0
        format(123) = 123p0
        --------------------------------------------------

        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                joconnersunw John Oconner (Inactive)
                Reporter:
                dfazunensunw Dmitri Fazunenko (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: