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

Wrong ParsePosition index after parsing a number with a space with DecimalFormat

    Details

    • Subcomponent:
    • Introduced In Build:
      b21
    • Introduced In Version:
      13
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      $ uname -a
      Linux martin-tuxedo 5.0.0-15-generic #16-Ubuntu SMP Mon May 6 17:41:33 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

      $ /home/martin/devel/jdk-13/bin/java -version
      openjdk version "13-ea" 2019-09-17
      OpenJDK Runtime Environment (build 13-ea+23)
      OpenJDK 64-Bit Server VM (build 13-ea+23, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      Testing Java 13 build 23 with Apache Wicket led to a test failure in parsing an number like "3 000" with DecimalFormat. The test was passing with Java 13 build 18 and earlier versions of Java (12, 11, ...).
      The problem is that now ParsePosition#getIndex() returns different value if the parsed string contains Unicode characters like \u00A0.

      REGRESSION : Last worked in version 13

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the code below with Java 13 build 23 and any previous build:



      ---------- BEGIN SOURCE ----------

      import java.text.DecimalFormat;
      import java.text.NumberFormat;
      import java.text.ParsePosition;
      import java.util.Locale;

      public class Java13Regression1
      {

      public static void main(String[] args)
      {
      NumberFormat numberFormat = NumberFormat.getInstance(Locale.FRENCH);
      ((DecimalFormat) numberFormat).setParseBigDecimal(true);
      final ParsePosition position = new ParsePosition(0);
      String value = "3 000".replaceAll("(\\d+)\\s(?=\\d)", "$1\u00A0"); // this causes the problem
      numberFormat.parseObject(value, position);

      // prints 5 for Java 13 build 18 and earlier (Java 12, 11, ...)
      // But prints 1 for Java 13 build 23
      System.err.println("Position index: " + position.getIndex());
      }
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                naoto Naoto Sato
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: