Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8175539

Duplicate matching tags returned by Locale.filterTags() for LanguageRange("*")

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 10
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b15
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      Description:

      Locale.filterTags method is returning duplicate tags in the matching output tags. However it is not written in the javadoc that only distinct tags will be returned in the output, but that behaviour varies between the language ranges.

      For LanguageRange("*", 0.6) and for the input tags "de-CH", "hi-IN", "fr-CH", "de-CH", "en", it returns,
      de-CH, hi-IN, fr-CH, de-CH, en // duplicate "de-CH"

      OTOH, for LanguageRange("*-CH", 0.6) and for the same input tags ("de-CH", "hi-IN", "fr-CH", "de-CH", "en"), it returns,
      de-CH, fr-CH // no duplicate de-CH

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the code provided

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class DuplicateTags {

          public static void main (String[] args) {
              List<Locale.LanguageRange> langRanges = List.of(new Locale.LanguageRange("*", 0.6));
              List<String> tags = List.of("de-CH", "hi-IN", "fr-CH", "de-CH", "en");
              List<String> list = Locale.filterTags(langRanges, tags, Locale.FilteringMode.AUTOSELECT_FILTERING);

              for (String str : list) {
                  System.out.print(str+" "); // return duplicate tags de-ch
              }
              System.out.println("");


              langRanges = List.of(new Locale.LanguageRange("*-CH", 0.6));
              tags = List.of("de-CH", "hi-IN", "fr-CH", "de-CH", "en");
              list = Locale.filterTags(langRanges, tags, Locale.FilteringMode.AUTOSELECT_FILTERING);

              for (String str : list) {
                  System.out.print(str+" "); // no duplicates are returned
              }
              System.out.println("");
          }
      }

      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              nishjain Nishit Jain
              Reporter:
              nishjain Nishit Jain
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: