1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8038436 27 * @summary Test for changes in 8038436 28 * @modules java.base/sun.util.locale.provider 29 * java.base/sun.util.spi 30 * @compile -XDignore.symbol.file Bug8038436.java 31 * @run main/othervm Bug8038436 -Djava.ext.dirs=foo security 32 * @run main/othervm Bug8038436 -Djava.locale.providers=JRE availlocs 33 */ 34 35 import java.security.*; 36 import java.text.*; 37 import java.util.*; 38 import java.util.stream.*; 39 import sun.util.locale.provider.*; 40 41 public class Bug8038436 { 42 public static void main(String[] args) { 43 switch (args[1]) { 44 case "security": 45 securityTests(); 46 break; 47 case "availlocs": 48 availableLocalesTests(); 49 break; 50 default: 51 throw new RuntimeException("no test was specified."); 52 } 53 } 54 55 private static void securityTests() { 56 Policy.setPolicy(new MyPolicy()); 57 System.setSecurityManager(new SecurityManager()); 58 59 /* 60 * Test for AccessClassInPackage security exception. Confirms that 61 * exeption won't be thrown if an application sets a Permission that 62 * does not allow any RuntimePermission, on loading LocaleDataMetaInfo 63 * from jdk.localedata module. 64 */ 65 System.out.println(new Formatter(Locale.JAPAN).format("%1$tB %1$te, %1$tY", 66 new GregorianCalendar())); 67 68 /* 69 * Check only English/ROOT locales are returned if the jdk.localedata 70 * module is not installed (implied by "java.ext.dirs" set to "foo"). 71 */ 72 if (Arrays.asList(Locale.getAvailableLocales()) 73 .stream() 74 .anyMatch(l -> l != Locale.ROOT && l.getLanguage() != "en")) { 75 throw new RuntimeException("non English locale(s) included in available locales"); 76 } 77 } 78 79 80 static class MyPolicy extends Policy { 81 final PermissionCollection perms = new Permissions(); 82 83 MyPolicy() { 84 // allows no RuntimePermission 85 } 86 87 public PermissionCollection getPermissions(ProtectionDomain domain) { 88 return perms; 89 } 90 91 public PermissionCollection getPermissions(CodeSource codesource) { 92 return perms; 93 } 94 95 public boolean implies(ProtectionDomain domain, Permission perm) { | 1 /* 2 * Copyright (c) 2014, 2016 Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8038436 8158504 27 * @summary Test for changes in 8038436 28 * @modules java.base/sun.util.locale.provider 29 * java.base/sun.util.spi 30 * @compile -XDignore.symbol.file Bug8038436.java 31 * @run main/othervm -limitmods java.base Bug8038436 security 32 * @run main/othervm -Djava.locale.providers=COMPAT Bug8038436 availlocs 33 */ 34 35 import java.security.*; 36 import java.util.*; 37 import java.util.stream.*; 38 import sun.util.locale.provider.*; 39 40 public class Bug8038436 { 41 public static void main(String[] args) { 42 43 switch (args[0]) { 44 45 case "security": 46 securityTests(); 47 break; 48 case "availlocs": 49 availableLocalesTests(); 50 break; 51 default: 52 throw new RuntimeException("no test was specified."); 53 } 54 55 } 56 57 private static void securityTests() { 58 Policy.setPolicy(new MyPolicy()); 59 System.setSecurityManager(new SecurityManager()); 60 61 /* 62 * Test for AccessClassInPackage security exception. Confirms that 63 * exeption won't be thrown if an application sets a Permission that 64 * does not allow any RuntimePermission, on loading LocaleDataMetaInfo 65 * from jdk.localedata module. 66 */ 67 System.out.println(new Formatter(Locale.JAPAN).format("%1$tB %1$te, %1$tY", 68 new GregorianCalendar())); 69 70 /* 71 * Check only English/ROOT locales are returned if the jdk.localedata 72 * module is not loaded (implied by "-limitmods java.base"). 73 */ 74 List<Locale> nonEnglishLocales= (Arrays.stream(Locale.getAvailableLocales()) 75 .filter(l -> l != Locale.ROOT && l.getLanguage() != "en") 76 .collect(Collectors.toList())); 77 78 if (nonEnglishLocales.size() > 0) { 79 throw new RuntimeException("non English locale(s)" + nonEnglishLocales +" included in available locales"); 80 } 81 } 82 83 84 static class MyPolicy extends Policy { 85 final PermissionCollection perms = new Permissions(); 86 87 MyPolicy() { 88 // allows no RuntimePermission 89 } 90 91 public PermissionCollection getPermissions(ProtectionDomain domain) { 92 return perms; 93 } 94 95 public PermissionCollection getPermissions(CodeSource codesource) { 96 return perms; 97 } 98 99 public boolean implies(ProtectionDomain domain, Permission perm) { |