JDK-8198491 : Parsing dates with SimpleDateFormat is broken in JDK 9
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 9.0.4
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: linux
  • CPU: x86_64
  • Submitted: 2018-02-20
  • Updated: 2018-02-21
  • Resolved: 2018-02-21
Description
FULL PRODUCT VERSION :
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux tichy 4.4.0-112-generic #135-Ubuntu SMP Fri Jan 19 11:48:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
Dates formatted with SimpleDateFormat under Java 8 can not be parsed back with Java 9 - the attached sources prove this to be the case with Locale GERMAN but i suspect it is valid for more than just this Locale

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
execute the attached small app under java 8  and under Java 9 - under Java9 it will break. Reasons: different results when using the same format string. The Example shows differences at the name of the day of the week and at the month of the year representations - i suspect there is more...

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Java Version 1.8.0_144
SimpleDateFormat pattern; EEE, dd MMM yyyy H:m:s
Formatted Date: Di, 20 M��r 2018 8:54:4
Parsing Java-8-formatted-date: Di, 20 M��r 2018 8:49:8
ACTUAL -
Java Version 9.0.4
SimpleDateFormat pattern; EEE, dd MMM yyyy H:m:s
Formatted Date: Di., 20 M��rz 2018 8:51:10
Parsing Java-8-formatted-date: Di, 20 M��r 2018 8:49:8
Exception in thread "main" java.text.ParseException: Unparseable date: "Di, 20 M��r 2018 8:49:8"
	at java.base/java.text.DateFormat.parse(DateFormat.java:388)
	at de.elbosso.scratch.misc.Java9DateFormatDEBug.main(Java9DateFormatDEBug.java:19)
Java Result: 1

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.text.ParseException: Unparseable date: "Di, 20 M��r 2018 8:49:8"
	at java.base/java.text.DateFormat.parse(DateFormat.java:388)
	at de.elbosso.scratch.misc.Java9DateFormatDEBug.main(Java9DateFormatDEBug.java:19)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.text.ParseException;

public class Java9DateFormatDEBug
{
	public static void main(String[] args) throws IOException, ParseException
	{
		java.lang.String pattern="EEE, dd MMM yyyy H:m:s";
		java.text.DateFormat rssf = new java.text.SimpleDateFormat(
				pattern, java.util.Locale.GERMAN);
		System.out.println("Java Version "+System.getProperty("java.version"));
		System.out.println("SimpleDateFormat pattern; "+pattern);
		java.util.Calendar cal = java.util.Calendar.getInstance();
		cal.set(cal.MONTH, 2);
		System.out.println("Formatted Date: "+rssf.format(cal.getTime()));
		System.out.println("Parsing Java-8-formatted-date: Di, 20 M��r 2018 8:49:8");
		rssf.parse("Di, 20 M��r 2018 8:49:8");
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
There is none as far as i can see


Comments
Please refer : http://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html#JDK-8008577 In JDK 9, the default locale data uses data derived from the Unicode Consortium's Common Locale Data Repository (CLDR). So there are changes with respect to some locales and hence this exception. Refer: http://www.unicode.org/cldr/charts/29/by_type/ To use the JRE locale with JDK 9 set java.locale.providers to a value with COMPAT ahead of CLDR. : -Djava.locale.providers=COMPAT, CLDR
21-02-2018