JDK-8071929 : Locale.getISOCountries() has inconsistent behaviour for "AN", "BU" and "CS" country codes
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2015-01-29
  • Updated: 2017-05-17
  • Resolved: 2016-12-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8-poolUnresolved 9 b149Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Links:
------
  [1] https://docs.oracle.com/javase/6/docs/api/java/util/Locale.html#getISO3Country%28%29
  [2] https://docs.oracle.com/javase/7/docs/api/java/util/Locale.html#getISO3Country%28%29
  [3] http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html
  [4] https://docs.oracle.com/javase/6/docs/api/java/util/Locale.html
  [5] https://www.iso.org/obp/ui/#search
  [6] http://web.archive.org/web/20061205090748/http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html

Issue description:
------------------

The Locale.getISO3Country() javadoc states as follows:
 
Java SE 6 [1]:
    Returns a three-letter abbreviation for this locale's country. If the locale
    doesn't specify a country, this will be the empty string. Otherwise, this
    will be an uppercase ISO 3166 3-letter country code. The ISO 3166-2 country
    codes can be found on-line at http://www.davros.org/misc/iso3166.txt.
    Throws:
      MissingResourceException - Throws MissingResourceException if the
      three-letter country abbreviation is not available for this locale.
 
Java SE 7 [2]:
    Returns a three-letter abbreviation for this locale's country. If the
    country matches an ISO 3166-1 alpha-2 code, the corresponding ISO 3166-1 alpha-3
    uppercase code is returned. If the locale doesn't specify a country, this will
    be the empty string.The ISO 3166-1 codes can be found on-line.
    Returns:
      A three-letter abbreviation of this locale's country.
    Throws:
      MissingResourceException - Throws MissingResourceException if the
      three-letter country abbreviation is not available for this locale.
 
(Notice that the link [3], mentioned in the class javadoc for [4], makes a redirection
to [5] (official ISO site), but it still can be found at [6].)
 

The above javadocs do not say anything concrete about the "Status" field for
country codes in ISO-3166 standard, so someone can expect that getISOCountries() in 
the specific Java SE release has consistent behaviour for all countries with
"Transitionally Reserved" status. Unfortunately, there is a contradiction between
JDK6 vs JDK7(and 8), as demonstrated by the minimized test below. 
 

Minimized test:
---------------

$ cat TestTRISOs.java 
import java.util.*;
 
public class TestTRISOs {
 
    public static void main(String... args) {
        final String[] trCodes = {"AN", "BU", "CS"};
 
        for (String trc : trCodes) {
            Locale loc = new Locale("", trc);
            try {
                String ic = loc.getISO3Country();
                System.out.println(trc + " => " + ic);
            } catch(MissingResourceException e) {
                System.out.println("(" + trc +") Unexpected exception thrown " + e);
            }
        }
    }
}
 
 
$ /cygdrive/c/java/6/binaries/windows-x64/bin/java TestTRISOs
AN => ANT
(BU) Unexpected exception thrown java.util.MissingResourceException: Couldn't find 3-letter country code for BU
CS => SCG
 
$ /cygdrive/c/java/7/binaries/windows-x64/bin/java TestTRISOs
AN => ANT
(BU) Unexpected exception thrown java.util.MissingResourceException: Couldn't find 3-letter country code for BU
(CS) Unexpected exception thrown java.util.MissingResourceException: Couldn't find 3-letter country code for CS
 
$ /cygdrive/c/java/8/binaries/windows-x64/bin/java TestTRISOs
AN => ANT
(BU) Unexpected exception thrown java.util.MissingResourceException: Couldn't find 3-letter country code for BU
(CS) Unexpected exception thrown java.util.MissingResourceException: Couldn't find 3-letter country code for CS
 
Such behaviour looks inconsistent and can be fixed or at least documented.

Comments
Need to clarify the spec wrt the status of the standard, and the behavior on codes that are obsolete.
29-01-2015