Check for a behavior change on Local getDefault method

This rule flags instances of the java.util.Locale getDefault() method.

This method is flagged because there is a behavior change associated with it. According to Java SE 7 and JDK 7 Compatibility documentation in Java 7, the user can now access the display locale (the visual representation of a string for example) or the format locale (the actual format of a string for example). To help accomplish this, Java 7 added the new method: getDefault(Locale.Catgory cat) where Locale.Category is a new enumeration with DISPLAY or FORMAT options. Using this new method, the user can get the specific Locale of interest.

The older method, which this rule flags, getDefault() has been updated to be equivalent to the call getDefault(Locale.DISPLAY) . Prior to Java 7, the getDefault() method used to return to what is equivalent to getDefault(Locale.FORMAT)

The display locale determines how the data is displayed on a user interface, such as a window or a dialog box. For example, the data can be displayed in a different language than the host system.

The format locale determines how the data is formatted. For example, using the United States format locale, the date October 4, 2011 is presented as 10/04/2011 while the same date using the United Kingdom format locale would appear as 04/10/2011.

The user needs to evaluate the code and determine if it is affected by the behavior change, pursue any appropriate testing, and make any necessary changes to the code.

According to the documentation, the user can preserve the older behavior of JDK 6 by either setting the property sun.locale.formatasdefault to true or by changing the code to use the new method getDefault(Locale.Category cat) . In this case, the cat parameter will be Locale.Category.FORMAT

For additional information, see the Java 7 APIs: