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

Format.parseObject(String) and parse(String) methods don't parse entire String

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.1.8, 1.3.0
    • core-libs
    • beta2
    • generic, x86
    • generic, windows_nt



      Name: krC82822 Date: 10/01/2000


      01 Oct 2000, eval1127@eng -- reproducible. See also # 4241052.

      java version "1.2.2"
      Classic VM (build JDK-1.2.2-W, native threads, symcjit)
      (also happens with 1.2.2-001 and 1.3.0-C)

      import java.text.*;
      import java.util.*;

      public class Numero {

              public static void main(String[] args) {
                      NumberFormat nf = NumberFormat.getNumberInstance(new Locale("en", "US"));

                      try {
                              Number n = nf.parse("1 l");
                              System.out.println(n);
                      }
                      catch(Exception e) {
                              System.err.println("caught: " + e);
                      }
              }
      }

      Output is

      1


      Note:
      This should throw a FormatException unless maybe you were in France, which
      should still throw an exception. Also the space in a French Locale is Unicode
      160 and the space above is 32. I hope getParameter in servlets will give me a
      160 groupseparator.

      ---------------------
      (Review ID: 110129)
      ======================================================================

      Name: yyT116575 Date: 02/07/2001


      java version "1.3.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
      Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)

      Set the NumberFormat locale to French. Then NumberFormat.parse() is not able to parse the breaking space that is sent when the input is, say, "2 2". The output of this parse is just 2. I guess the reason is that in the french
      locale a non breaking space is the seperator. Still I think that a NumberFormat set to the french locale should be able to handle this.

      NumberFormat numberFormat = NumberFormat.getInstance(Locale.FRENCH);
      System.out.println(numberFormat.parse("9 000").intValue());

      Output is 9, against the expected 9 000
      (Review ID: 116527)
      ======================================================================

            nlindenbsunw Norbert Lindenberg (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: