JDK-8190914 : Unable to implement workaround to JDK-4510618 bug with java 9 => Unable to parse french numbers
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 9.0.1
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2017-10-29
  • Updated: 2017-11-10
  • Resolved: 2017-11-08
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 10

A DESCRIPTION OF THE PROBLEM :
JDK-4510618 describes the initial problem that affects all jdk version : JDK is not able to parse french numbers because it uses non breaking spaces as separators. The workaround suggested in the bug report doesn't work with JDK 9.

REGRESSION.  Last worked in version 8u162

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the provided Junit test




EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test should not fail
ACTUAL -
Test fails

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import static org.junit.Assert.*;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;

import org.junit.Test;

public class CurrencyWidgetTest {
	private static final char NON_BREAKING_SPACE = 160;
	private static final char SPACE = ' ';

	@Test
	public void basicJDKtest() throws ParseException {
		DecimalFormat format = (DecimalFormat)NumberFormat.getCurrencyInstance(Locale.FRANCE);
		DecimalFormatSymbols decimalFormatSymbols = format.getDecimalFormatSymbols();
		if (decimalFormatSymbols.getGroupingSeparator()==NON_BREAKING_SPACE) {
			decimalFormatSymbols.setGroupingSeparator(SPACE);
		}
		if (decimalFormatSymbols.getDecimalSeparator()==NON_BREAKING_SPACE) {
			decimalFormatSymbols.setDecimalSeparator(SPACE);
		}
		format.setDecimalFormatSymbols(decimalFormatSymbols);

		String text = "5 000,00 ���";
		Number parse = format.parse(text);
		assertNotNull(parse);
	}
}
---------- END SOURCE ----------


Comments
In JDK 9, the default locale provider is CLDR. In the format provided by the CLDR, there is a non-breaking space between the number and the currency symbol for the French Locale. So, the String to be parsed should be "5 000,00\u00a0���" . To get the behavior compatible with JDK 8, use -Djava.locale.providers=COMPAT,SPI system property while using java runtime. Refer: http://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html#JDK-8008577 http://cldr.unicode.org/
10-11-2017