JDK-8071742 : DateFormatSymbols regression: results differ between Java7 and Java8
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 8u31
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: linux_ubuntu
  • CPU: x86_64
  • Submitted: 2015-01-24
  • Updated: 2015-01-29
  • Resolved: 2015-01-29
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
openjdk version "1.8.0_40-internal"
OpenJDK Runtime Environment (build 1.8.0_40-internal-b09)
OpenJDK 64-Bit Server VM (build 25.40-b13, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux laptop 3.16.0-29-generic #39-Ubuntu SMP Mon Dec 15 22:27:29 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
In Java 7 and earlier, DateFormatSymbols.getMonths() used to return month names in their nominative case. For Czech, results were "leden", "unor", ... - months were in their standalone form.

Applications use this function just to get month names.
However, fixing bug JDK-7079560 changed this and months are returned in genitive case like "ledna", "unora".
In Czech, this is used when writing full date (1. ledna 2015) and is never used in standalone format. 

Applications written for Java 7 and older expect standalone form and use it incorrectly, when choosing month and when they are just mentioning it. User therefore selects from "ledna", "unora" instead of correct "leden", "unor".

REGRESSION.  Last worked in version 7u76

ADDITIONAL REGRESSION INFORMATION: 
It works in any Java 7 or older.

java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-0ubuntu1)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run application, that uses DateFormatSymbols.getMonths() to get month names.
Application displays months in their nominative form in Java < 7 and in their genitive form in Java 8.

Older application, that rely on nominative form will use the month names incorrectly.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Application should get same form no matter which version is used.
ACTUAL -
Application gets months in their nominative form in Java < 7 and in their genitive form in Java 8.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
class Test {
	public static void main(String[] s) {

		DateFormatSymbols dateFormatSymbols = new DateFormatSymbols();
		String[] monthNames = dateFormatSymbols.getMonths();
		System.out.println(monthNames[0]); //returns "leden" on JDK7 (and older); returns "ledna" on JDK8
	}
}
---------- END SOURCE ----------


Comments
The behavior change is one of the approved incompatible changes as described in the release notes of Java 8. If you need to support both 7 and 8 with stand-alone month names, SimpleDateFormat("MMMM").format() will produces stand-alone month names. Otherwise, I'd suggest Calendar.getDisplayName be used instead of DateFormatSymbols. In Java 7, you could catch IllegalArgumentException with the STANDALONE constants and fall back to their corresponding Java 7 constants, though.
29-01-2015