JDK-8225245 : Wrong ParsePosition index after parsing a number with a space with DecimalFormat
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 13
  • Priority: P2
  • Status: Resolved
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2019-06-04
  • Updated: 2019-07-17
  • Resolved: 2019-06-04
Related Reports
Duplicate :  
Relates :  
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



Comments
Mention included in the relnote of CLDR 35.1 (JDK-8223587)
05-06-2019

CLDR has changed the grouping separator for French in v34, from U+00A0 to U+202F: https://www.unicode.org/cldr/charts/34/delta/fr.html#Symbols JDK has been based on v35.1 since b21 (JDK-8221432), thus the applications that expect the French grouping separator to be U+00A0 will not work. Instead of hardcoding \u00A0, applications can use DecimalFormatSymbols.getInstance(Locale.FRENCH).getGroupingSeparator().
04-06-2019

This issue also started from JDK 13 b21, most likely due to CLDR version upgrade (JDK-8221432). JDK 13-ea + 20- Pass JDK 13-ea + 21 - Fail JDK 13-ea + 22 - Fail Output on passing versions : Position index: 5 Output on failing versions : Position index: 1
04-06-2019