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

[Fmt-*] Clarify DecimalFormat description of FieldPosition use

    Details

    • Subcomponent:
    • Resolved In Build:
      b34
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Not verified

      Description

      FULL PRODUCT VERSION :
      java version "1.4.2_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
      Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

      FULL OS VERSION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
        From http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html:

      public StringBuffer format(long number,
                                 StringBuffer result,
                                 FieldPosition fieldPosition)
      Format a long to produce a string.
      Specified by:
      format in class NumberFormat

      Parameters:
      number - The long to format
      result - where the text is to be appended
      fieldPosition - On input: an alignment field, if desired. On output: the offsets of the alignment field.
      Returns:
      The formatted number string

      In spite of what the documentation says about fieldPosition, the alignment field seems to be ignored.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      (See test case)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      B,E 0,0
      B,E 10,23
                1,234,567,890
      B,E 10,23
      ACTUAL -
      B,E 0,0
      B,E 10,23
      1,234,567,890
      B,E 0,13


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.text.DecimalFormat;
      import java.text.FieldPosition;
      import java.text.NumberFormat;
      public class TestFormat{
      public static void main(String[] args)
      {
      StringBuffer sb = new StringBuffer();
      DecimalFormat df = new DecimalFormat();
      FieldPosition fp = new FieldPosition(NumberFormat.INTEGER_FIELD);
      System.out.println("B,E "+fp.getBeginIndex()+","+fp.getEndIndex());//B,E 0,0
      fp.setBeginIndex(10); fp.setEndIndex(23);
      System.out.println("B,E "+fp.getBeginIndex()+","+fp.getEndIndex());//B,E 10,23
      df.format(1234567890L,sb,fp);// Use FieldPosition to affect output
      System.out.println(sb); //1,234,567,890 - no leading spaces
      System.out.println("B,E "+fp.getBeginIndex()+","+fp.getEndIndex());//B,E 0,13
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      [Ignore the documentation!]

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                nishjain Nishit Jain
                Reporter:
                gmanwanisunw Girish Manwani (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: