8166645: Include locales plugin throws InternalError with "*" specified.
authornaoto
Tue, 04 Oct 2016 09:52:03 -0700
changeset 41229 61e0df02e2dd
parent 41228 bb9385e8c619
child 41230 0a8c1ba2b6fb
8166645: Include locales plugin throws InternalError with "*" specified. Reviewed-by: mchung
jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java
jdk/test/tools/jlink/plugins/IncludeLocalesPluginTest.java
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java	Tue Oct 04 21:59:16 2016 +0530
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java	Tue Oct 04 09:52:03 2016 -0700
@@ -307,9 +307,10 @@
 
     private boolean filterOutUnsupportedTags(byte[] b) {
         List<Locale> locales;
+        List<String> originalTags = Arrays.asList(new String(b).split(" "));
 
         try {
-            locales = Arrays.asList(new String(b).split(" ")).stream()
+            locales = originalTags.stream()
                 .filter(tag -> !tag.isEmpty())
                 .map(IncludeLocalesPlugin::tagToLocale)
                 .collect(Collectors.toList());
@@ -319,6 +320,9 @@
         }
 
         byte[] filteredBytes = filterLocales(locales).stream()
+            // Make sure the filtered language tags do exist in the
+            // original supported tags for compatibility codes, e.g., "iw"
+            .filter(originalTags::contains)
             .collect(Collectors.joining(" "))
             .getBytes();
 
@@ -331,6 +335,11 @@
         return true;
     }
 
+    /*
+     * Filter list of locales according to the secified priorityList. Note
+     * that returned list of language tags may include extra ones, such as
+     * compatibility ones (e.g., "iw" -> "iw", "he").
+     */
     private List<String> filterLocales(List<Locale> locales) {
         List<String> ret =
             Locale.filter(priorityList, locales, Locale.FilteringMode.EXTENDED_FILTERING).stream()
--- a/jdk/test/tools/jlink/plugins/IncludeLocalesPluginTest.java	Tue Oct 04 21:59:16 2016 +0530
+++ b/jdk/test/tools/jlink/plugins/IncludeLocalesPluginTest.java	Tue Oct 04 09:52:03 2016 -0700
@@ -92,7 +92,7 @@
 
         // Asterisk works exactly the same as above
         {
-            "*",
+            "--include-locales=*",
             "jdk.localedata",
             List.of(
                 "/jdk.localedata/sun/text/resources/ext/FormatData_en_GB.class",