< prev index next >

jdk/test/sun/util/locale/provider/Bug8038436.java

Print this page




  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" && (l.getCountry() == "US" || l.getCountry() == "" ))))
  76                 .collect(Collectors.toList()));
  77 
  78         if (!nonEnglishLocales.isEmpty()) {
  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;




  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  --limit-modules 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 "--limit-modules java.base").
  73          */
  74         List<Locale> nonEnglishLocales= (Arrays.stream(Locale.getAvailableLocales())
  75                 .filter(l -> (l != Locale.ROOT && !(l.getLanguage() == "en" && (l.getCountry() == "US" || l.getCountry() == "" ))))
  76                 .collect(Collectors.toList()));
  77 
  78         if (!nonEnglishLocales.isEmpty()) {
  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;


< prev index next >