7068662: Reserve and restore the default locale
authorxuelei
Fri, 29 Jul 2011 02:50:58 -0700
changeset 10138 b7572da25d15
parent 10137 d92637d3d673
child 10139 49e1c342c329
7068662: Reserve and restore the default locale Reviewed-by: alanb, weijun
jdk/test/com/sun/org/apache/xml/internal/security/exceptions/LocaleTest.java
jdk/test/java/beans/XMLDecoder/Test6341798.java
jdk/test/java/io/pathNames/win32/bug6344646.java
jdk/test/java/net/CookieHandler/B6791927.java
jdk/test/java/net/URLConnection/SetIfModifiedSince.java
jdk/test/java/util/Locale/LocaleCategory.java
jdk/test/java/util/PluggableLocale/CurrencyNameProviderTest.java
jdk/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java
jdk/test/java/util/ResourceBundle/Bug6190861.java
jdk/test/java/util/ResourceBundle/Control/Bug6530694.java
jdk/test/java/util/ResourceBundle/Control/StressTest.java
jdk/test/java/util/ResourceBundle/Test4314141.java
jdk/test/java/util/ResourceBundle/Test4318520.java
jdk/test/java/util/jar/JarFile/TurkCert.java
jdk/test/javax/crypto/Cipher/Turkish.java
jdk/test/javax/swing/JColorChooser/Test6524757.java
jdk/test/sun/security/tools/keytool/KeyToolTest.java
jdk/test/sun/text/resources/Collator/Bug4248694.java
jdk/test/sun/text/resources/Collator/Bug4804273.java
jdk/test/sun/text/resources/Collator/Bug4848897.java
jdk/test/sun/text/resources/Format/Bug4651568.java
jdk/test/sun/util/resources/Locale/Bug4965260.java
jdk/test/sun/util/resources/TimeZone/Bug4640234.java
--- a/jdk/test/com/sun/org/apache/xml/internal/security/exceptions/LocaleTest.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/com/sun/org/apache/xml/internal/security/exceptions/LocaleTest.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -36,15 +36,19 @@
 
     public static void main(String[] args) throws Exception {
 
-        Locale.setDefault(Locale.ITALY);
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            Locale.setDefault(Locale.ITALY);
 
-        try {
             throw new XMLSecurityException("foo");
         } catch (XMLSecurityException xse) {
             System.out.println("Test PASSED");
         } catch (Throwable t) {
             System.out.println("Test FAILED");
             t.printStackTrace();
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
         }
     }
 }
--- a/jdk/test/java/beans/XMLDecoder/Test6341798.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/java/beans/XMLDecoder/Test6341798.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -47,8 +47,14 @@
             + "</java> ";
 
     public static void main(String[] args) {
-        test(ENGLISH, DATA.getBytes());
-        test(TURKISH, DATA.getBytes());
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            test(ENGLISH, DATA.getBytes());
+            test(TURKISH, DATA.getBytes());
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
+        }
     }
 
     private static void test(Locale locale, byte[] data) {
--- a/jdk/test/java/io/pathNames/win32/bug6344646.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/java/io/pathNames/win32/bug6344646.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,17 +32,24 @@
 
 public class bug6344646 {
     public static void main(String[] s) {
-        /* This test is only valid on win32 systems */
-        if (File.separatorChar != '\\') {
-            return;
-        }
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            /* This test is only valid on win32 systems */
+            if (File.separatorChar != '\\') {
+                return;
+            }
 
-        Locale.setDefault(new Locale("lt"));
-        File f1 = new File("J\u0301");
-        File f2 = new File("j\u0301");
+            Locale.setDefault(new Locale("lt"));
+            File f1 = new File("J\u0301");
+            File f2 = new File("j\u0301");
 
-        if (f1.hashCode() != f2.hashCode()) {
-            throw new RuntimeException("File.hashCode() for \"J\u0301\" and \"j\u0301\" should be the same");
+            if (f1.hashCode() != f2.hashCode()) {
+                throw new RuntimeException("File.hashCode() for \"J\u0301\" " +
+                        "and \"j\u0301\" should be the same");
+            }
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
         }
     }
 }
--- a/jdk/test/java/net/CookieHandler/B6791927.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/java/net/CookieHandler/B6791927.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -33,16 +33,23 @@
 
 public class B6791927 {
     public static final void main( String[] aaParamters ) throws Exception{
-        // Forces a non US locale
-        Locale.setDefault(Locale.FRANCE);
-        List<HttpCookie> cookies = HttpCookie.parse("set-cookie: CUSTOMER=WILE_E_COYOTE; expires=Wednesday, 09-Nov-2019 23:12:40 GMT");
-        if (cookies == null || cookies.isEmpty()) {
-            throw new RuntimeException("No cookie found");
-        }
-        for (HttpCookie c : cookies) {
-            if (c.getMaxAge() == 0) {
-                throw new RuntimeException("Expiration date shouldn't be 0");
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            // Forces a non US locale
+            Locale.setDefault(Locale.FRANCE);
+            List<HttpCookie> cookies = HttpCookie.parse("set-cookie: CUSTOMER=WILE_E_COYOTE; expires=Wednesday, 09-Nov-2019 23:12:40 GMT");
+            if (cookies == null || cookies.isEmpty()) {
+                throw new RuntimeException("No cookie found");
             }
+            for (HttpCookie c : cookies) {
+                if (c.getMaxAge() == 0) {
+                    throw new RuntimeException(
+                        "Expiration date shouldn't be 0");
+                }
+            }
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
         }
     }
 }
--- a/jdk/test/java/net/URLConnection/SetIfModifiedSince.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/java/net/URLConnection/SetIfModifiedSince.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -73,6 +73,7 @@
     }
 
     public static void main (String[] args) {
+        Locale reservedLocale = Locale.getDefault();
         try {
             Locale.setDefault(Locale.JAPAN);
             ServerSocket serversocket = new ServerSocket (0);
@@ -87,6 +88,10 @@
             int i=0, c;
             Thread.sleep (5000);
         } catch (Exception e) {
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
         }
+
     }
 }
--- a/jdk/test/java/util/Locale/LocaleCategory.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/java/util/Locale/LocaleCategory.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,30 +29,37 @@
     private static String enc = null;
 
     public static void main(String[] args) {
-        Locale.Builder builder = new Locale.Builder();
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            Locale.Builder builder = new Locale.Builder();
 
-        base = builder.setLanguage(System.getProperty("user.language", ""))
-                      .setScript(System.getProperty("user.script", ""))
-                      .setRegion(System.getProperty("user.country", ""))
-                      .setVariant(System.getProperty("user.variant", "")).build();
-        disp = builder.setLanguage(System.getProperty("user.language.display",
-                                                      Locale.getDefault().getLanguage()))
-                      .setScript(System.getProperty("user.script.display",
-                                                    Locale.getDefault().getScript()))
-                      .setRegion(System.getProperty("user.country.display",
-                                                    Locale.getDefault().getCountry()))
-                      .setVariant(System.getProperty("user.variant.display",
-                                                     Locale.getDefault().getVariant())).build();
-        fmt = builder.setLanguage(System.getProperty("user.language.format",
-                                                     Locale.getDefault().getLanguage()))
-                     .setScript(System.getProperty("user.script.format",
-                                                   Locale.getDefault().getScript()))
-                     .setRegion(System.getProperty("user.country.format",
-                                                   Locale.getDefault().getCountry()))
-                     .setVariant(System.getProperty("user.variant.format",
-                                                     Locale.getDefault().getVariant())).build();
-        checkDefault();
-        testGetSetDefault();
+            base = builder.setLanguage(System.getProperty("user.language", ""))
+                  .setScript(System.getProperty("user.script", ""))
+                  .setRegion(System.getProperty("user.country", ""))
+                  .setVariant(System.getProperty("user.variant", "")).build();
+            disp = builder.setLanguage(
+                    System.getProperty("user.language.display",
+                                Locale.getDefault().getLanguage()))
+                        .setScript(System.getProperty("user.script.display",
+                                Locale.getDefault().getScript()))
+                        .setRegion(System.getProperty("user.country.display",
+                                Locale.getDefault().getCountry()))
+                        .setVariant(System.getProperty("user.variant.display",
+                                Locale.getDefault().getVariant())).build();
+            fmt = builder.setLanguage(System.getProperty("user.language.format",
+                                Locale.getDefault().getLanguage()))
+                       .setScript(System.getProperty("user.script.format",
+                                Locale.getDefault().getScript()))
+                       .setRegion(System.getProperty("user.country.format",
+                                Locale.getDefault().getCountry()))
+                       .setVariant(System.getProperty("user.variant.format",
+                                  Locale.getDefault().getVariant())).build();
+            checkDefault();
+            testGetSetDefault();
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
+        }
     }
 
     static void checkDefault() {
--- a/jdk/test/java/util/PluggableLocale/CurrencyNameProviderTest.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/java/util/PluggableLocale/CurrencyNameProviderTest.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,7 +32,13 @@
 public class CurrencyNameProviderTest extends ProviderTest {
 
     public static void main(String[] s) {
-        new CurrencyNameProviderTest();
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            new CurrencyNameProviderTest();
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
+        }
     }
 
     CurrencyNameProviderTest() {
--- a/jdk/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -113,6 +113,7 @@
 
     void test2() {
         Locale defaultLocale = Locale.getDefault();
+        TimeZone reservedTimeZone = TimeZone.getDefault();
         Date d = new Date(2005-1900, Calendar.DECEMBER, 22);
         String formatted;
 
@@ -139,7 +140,6 @@
                 df = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance());
                 System.out.println(formatted = df.format(d));
                 if(!formatted.equals(DISPLAY_NAMES_KYOTO[i])) {
-                    Locale.setDefault(defaultLocale);
                     throw new RuntimeException("Timezone " + TIMEZONES[i] +
                         ": formatted zone names mismatch. " +
                         formatted + " should match with " +
@@ -148,10 +148,12 @@
                 df.parse(DISPLAY_NAMES_KYOTO[i]);
             }
         } catch (ParseException pe) {
+            throw new RuntimeException("parse error occured" + pe);
+        } finally {
+            // restore the reserved locale and time zone
             Locale.setDefault(defaultLocale);
-            throw new RuntimeException("parse error occured" + pe);
+            TimeZone.setDefault(reservedTimeZone);
         }
-        Locale.setDefault(defaultLocale);
     }
 
     final String LATIME = "America/Los_Angeles";
--- a/jdk/test/java/util/ResourceBundle/Bug6190861.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/java/util/ResourceBundle/Bug6190861.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,27 +32,34 @@
 public class Bug6190861 {
 
     static public void main(String[] args) {
-        Locale.setDefault(new Locale("en", "US"));
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            Locale.setDefault(new Locale("en", "US"));
 
-        List localeList = new ArrayList();
-        localeList.add(Locale.ENGLISH);
-        localeList.add(Locale.KOREA);
-        localeList.add(Locale.UK);
-        localeList.add(new Locale("en", "CA"));
-        localeList.add(Locale.ENGLISH);
+            List localeList = new ArrayList();
+            localeList.add(Locale.ENGLISH);
+            localeList.add(Locale.KOREA);
+            localeList.add(Locale.UK);
+            localeList.add(new Locale("en", "CA"));
+            localeList.add(Locale.ENGLISH);
 
-        Iterator iter = localeList.iterator();
-        while (iter.hasNext()){
-            Locale currentLocale = (Locale) iter.next();
-            System.out.println("\ncurrentLocale = "
+            Iterator iter = localeList.iterator();
+            while (iter.hasNext()){
+                Locale currentLocale = (Locale) iter.next();
+                System.out.println("\ncurrentLocale = "
                                + currentLocale.getDisplayName());
 
-            ResourceBundle messages = ResourceBundle.getBundle("Bug6190861Data",currentLocale);
+                ResourceBundle messages =
+                    ResourceBundle.getBundle("Bug6190861Data",currentLocale);
 
-            Locale messagesLocale = messages.getLocale();
-            System.out.println("messagesLocale = "
+                Locale messagesLocale = messages.getLocale();
+                System.out.println("messagesLocale = "
                                + messagesLocale.getDisplayName());
-            checkMessages(messages);
+                checkMessages(messages);
+            }
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
         }
     }
 
--- a/jdk/test/java/util/ResourceBundle/Control/Bug6530694.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/java/util/ResourceBundle/Control/Bug6530694.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -43,6 +43,12 @@
     }
 
     public static void main(String[] args) {
-        new Bug6530694();
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            new Bug6530694();
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
+        }
     }
 }
--- a/jdk/test/java/util/ResourceBundle/Control/StressTest.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/java/util/ResourceBundle/Control/StressTest.java	Fri Jul 29 02:50:58 2011 -0700
@@ -69,36 +69,44 @@
         if (args.length > 1) {
             duration = Math.max(5, Integer.parseInt(args[1]));
         }
-        Locale.setDefault(Locale.US);
-        Thread[] tasks = new Thread[locales.length * threadsFactor];
-        counters = new AtomicIntegerArray(tasks.length);
+
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            Locale.setDefault(Locale.US);
+            Thread[] tasks = new Thread[locales.length * threadsFactor];
+            counters = new AtomicIntegerArray(tasks.length);
 
-        for (int i = 0; i < tasks.length; i++) {
-            tasks[i] = new Thread(new Worker(i));
-        }
-        for (int i = 0; i < tasks.length; i++) {
-            tasks[i].start();
-        }
+            for (int i = 0; i < tasks.length; i++) {
+                tasks[i] = new Thread(new Worker(i));
+            }
+            for (int i = 0; i < tasks.length; i++) {
+                tasks[i].start();
+            }
 
-        int nProcessors = Runtime.getRuntime().availableProcessors();
-        intervalForCounterCheck = Math.max(tasks.length / nProcessors, 1);
-        System.out.printf("%d processors, intervalForCounterCheck = %d [sec]%n",
+            int nProcessors = Runtime.getRuntime().availableProcessors();
+            intervalForCounterCheck = Math.max(tasks.length / nProcessors, 1);
+            System.out.printf(
+                "%d processors, intervalForCounterCheck = %d [sec]%n",
                           nProcessors, intervalForCounterCheck);
-        try {
-            for (int i = 0; runrun && i < duration; i++) {
-                Thread.sleep(1000); // 1 second
-                if ((i % intervalForCounterCheck) == 0) {
-                    checkCounters();
+            try {
+                for (int i = 0; runrun && i < duration; i++) {
+                    Thread.sleep(1000); // 1 second
+                    if ((i % intervalForCounterCheck) == 0) {
+                        checkCounters();
+                    }
                 }
+                runrun = false;
+                for (int i = 0; i < tasks.length; i++) {
+                    tasks[i].join();
+                }
+            } catch (InterruptedException e) {
             }
-            runrun = false;
-            for (int i = 0; i < tasks.length; i++) {
-                tasks[i].join();
-            }
-        } catch (InterruptedException e) {
+
+            printCounters();
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
         }
-
-        printCounters();
     }
 
     static void checkCounters() {
--- a/jdk/test/java/util/ResourceBundle/Test4314141.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/java/util/ResourceBundle/Test4314141.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,8 +35,14 @@
 public class Test4314141 {
 
     public static void main(String[] args) {
-        testCandidateOmission();
-        testExample();
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            testCandidateOmission();
+            testExample();
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
+        }
     }
 
     /**
--- a/jdk/test/java/util/ResourceBundle/Test4318520.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/java/util/ResourceBundle/Test4318520.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -36,8 +36,14 @@
 public class Test4318520 {
 
     public static void main(String[] args) {
-        test(Locale.GERMAN);
-        test(Locale.ENGLISH);
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            test(Locale.GERMAN);
+            test(Locale.ENGLISH);
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
+        }
     }
 
     private static void test(Locale locale) {
--- a/jdk/test/java/util/jar/JarFile/TurkCert.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/java/util/jar/JarFile/TurkCert.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,6 @@
  * @bug 4624534
  * @summary Make sure jar certificates work for Turkish locale
  * @author kladko
- * @run main/othervm TurkCert
  */
 
 import java.util.*;
@@ -36,15 +35,24 @@
 
 public class TurkCert {
     public static void main(String[] args) throws Exception{
-        Locale.setDefault(new Locale("TR", "tr"));
-        File f = new File(System.getProperty("test.src","."), "test.jar");
-        JarFile jf = new JarFile(f, true);
-        JarEntry je = (JarEntry)jf.getEntry("test.class");
-        InputStream is = jf.getInputStream(je);
-        byte[] b = new byte[1024];
-        while (is.read(b) != -1) {
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            Locale.setDefault(new Locale("TR", "tr"));
+            File f = new File(System.getProperty("test.src","."), "test.jar");
+            try (JarFile jf = new JarFile(f, true)) {
+                JarEntry je = (JarEntry)jf.getEntry("test.class");
+                try (InputStream is = jf.getInputStream(je)) {
+                    byte[] b = new byte[1024];
+                    while (is.read(b) != -1) {
+                    }
+                }
+                if (je.getCertificates() == null) {
+                    throw new Exception("Null certificate for test.class.");
+                }
+            }
+        } finally {
+            // restore the default locale
+            Locale.setDefault(reservedLocale);
         }
-        if (je.getCertificates() == null)
-            throw new Exception("Null certificate for test.class.");
     }
 }
--- a/jdk/test/javax/crypto/Cipher/Turkish.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/javax/crypto/Cipher/Turkish.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,15 +35,21 @@
 public class Turkish {
 
     public static void main(String[] args) throws Exception {
-        Locale.setDefault(new Locale("tr", "TR"));
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            Locale.setDefault(new Locale("tr", "TR"));
 
-        System.out.println(Cipher.getInstance("RSA/ECB/PKCS1Padding"));
-        System.out.println(Cipher.getInstance("RSA/ECB/PKCS1PADDING"));
-        System.out.println(Cipher.getInstance("rsa/ecb/pkcs1padding"));
-        System.out.println(Cipher.getInstance("Blowfish"));
-        System.out.println(Cipher.getInstance("blowfish"));
-        System.out.println(Cipher.getInstance("BLOWFISH"));
+            System.out.println(Cipher.getInstance("RSA/ECB/PKCS1Padding"));
+            System.out.println(Cipher.getInstance("RSA/ECB/PKCS1PADDING"));
+            System.out.println(Cipher.getInstance("rsa/ecb/pkcs1padding"));
+            System.out.println(Cipher.getInstance("Blowfish"));
+            System.out.println(Cipher.getInstance("blowfish"));
+            System.out.println(Cipher.getInstance("BLOWFISH"));
 
-        System.out.println("OK");
+            System.out.println("OK");
+        } finally {
+            // restore the default locale
+            Locale.setDefault(reservedLocale);
+        }
     }
 }
--- a/jdk/test/javax/swing/JColorChooser/Test6524757.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/javax/swing/JColorChooser/Test6524757.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -98,17 +98,23 @@
     private static final Object[] FRENCH = convert(Locale.FRENCH, KEYS);
 
     public static void main(String[] args) {
-        // it affects Swing because it is not initialized
-        Locale.setDefault(Locale.KOREAN);
-        validate(KOREAN, create());
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            // it affects Swing because it is not initialized
+            Locale.setDefault(Locale.KOREAN);
+            validate(KOREAN, create());
 
-        // it does not affect Swing because it is initialized
-        Locale.setDefault(Locale.CANADA);
-        validate(KOREAN, create());
+            // it does not affect Swing because it is initialized
+            Locale.setDefault(Locale.CANADA);
+            validate(KOREAN, create());
 
-        // it definitely should affect Swing
-        JComponent.setDefaultLocale(Locale.FRENCH);
-        validate(FRENCH, create());
+            // it definitely should affect Swing
+            JComponent.setDefaultLocale(Locale.FRENCH);
+            validate(FRENCH, create());
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
+        }
     }
 
     private static void validate(Object[] expected, Object[] actual) {
--- a/jdk/test/sun/security/tools/keytool/KeyToolTest.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/sun/security/tools/keytool/KeyToolTest.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1278,52 +1278,58 @@
     }
 
     public static void main(String[] args) throws Exception {
-        // first test if HumanInputStream really acts like a human being
-        HumanInputStream.test();
-        KeyToolTest t = new KeyToolTest();
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            // first test if HumanInputStream really acts like a human being
+            HumanInputStream.test();
+            KeyToolTest t = new KeyToolTest();
 
-        if (System.getProperty("file") != null) {
-            t.sqeTest();
-            t.testAll();
-            t.i18nTest();
-            t.v3extTest("RSA");
-            t.v3extTest("DSA");
-            boolean testEC = true;
-            try {
-                KeyPairGenerator.getInstance("EC");
-            } catch (NoSuchAlgorithmException nae) {
-                testEC = false;
+            if (System.getProperty("file") != null) {
+                t.sqeTest();
+                t.testAll();
+                t.i18nTest();
+                t.v3extTest("RSA");
+                t.v3extTest("DSA");
+                boolean testEC = true;
+                try {
+                    KeyPairGenerator.getInstance("EC");
+                } catch (NoSuchAlgorithmException nae) {
+                    testEC = false;
+                }
+                if (testEC) t.v3extTest("EC");
             }
-            if (testEC) t.v3extTest("EC");
-        }
 
-        if (System.getProperty("nss") != null) {
-            t.srcP11Arg = NSS_SRC_P11_ARG;
-            t.p11Arg = NSS_P11_ARG;
+            if (System.getProperty("nss") != null) {
+                t.srcP11Arg = NSS_SRC_P11_ARG;
+                t.p11Arg = NSS_P11_ARG;
 
-            t.testPKCS11();
+                t.testPKCS11();
+
+                // FAIL:
+                // 1. we still don't have srcprovidername yet
+                // 2. cannot store privatekey into NSS keystore
+                //    java.security.KeyStoreException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_TEMPLATE_INCOMPLETE.
+                //t.testPKCS11ImportKeyStore();
+
+                t.i18nPKCS11Test();
+                //FAIL: currently PKCS11-NSS does not support 2 NSS KeyStores to be loaded at the same time
+                //t.sszzTest();
+            }
 
-            // FAIL:
-            // 1. we still don't have srcprovidername yet
-            // 2. cannot store privatekey into NSS keystore
-            //    java.security.KeyStoreException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_TEMPLATE_INCOMPLETE.
-            //t.testPKCS11ImportKeyStore();
+            if (System.getProperty("solaris") != null) {
+                // For Solaris Cryptography Framework
+                t.srcP11Arg = SUN_SRC_P11_ARG;
+                t.p11Arg = SUN_P11_ARG;
+                t.testPKCS11();
+                t.testPKCS11ImportKeyStore();
+                t.i18nPKCS11Test();
+            }
 
-            t.i18nPKCS11Test();
-            //FAIL: currently PKCS11-NSS does not support 2 NSS KeyStores to be loaded at the same time
-            //t.sszzTest();
+            System.out.println("Test pass!!!");
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
         }
-
-        if (System.getProperty("solaris") != null) {
-            // For Solaris Cryptography Framework
-            t.srcP11Arg = SUN_SRC_P11_ARG;
-            t.p11Arg = SUN_P11_ARG;
-            t.testPKCS11();
-            t.testPKCS11ImportKeyStore();
-            t.i18nPKCS11Test();
-        }
-
-        System.out.println("Test pass!!!");
     }
 }
 
--- a/jdk/test/sun/text/resources/Collator/Bug4248694.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/sun/text/resources/Collator/Bug4248694.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,43 +35,49 @@
   /********************************************************
   *********************************************************/
   public static void main (String[] args) {
-      int errors=0;
+      Locale reservedLocale = Locale.getDefault();
+      try {
+          int errors=0;
 
-      Locale loc = new Locale ("is", "is");   // Icelandic
+          Locale loc = new Locale ("is", "is");   // Icelandic
 
-      Locale.setDefault (loc);
-      Collator col = Collator.getInstance ();
+          Locale.setDefault (loc);
+          Collator col = Collator.getInstance ();
 
-      String[] data = {"\u00e6ard",
-                       "Zard",
-                       "aard",
-                       "\u00feard",
-                       "vird",
-                       "\u00c6ard",
-                       "Zerd",
-                       "\u00deard"};
+          String[] data = {"\u00e6ard",
+                           "Zard",
+                           "aard",
+                           "\u00feard",
+                           "vird",
+                           "\u00c6ard",
+                           "Zerd",
+                           "\u00deard"};
 
-      String[] sortedData = {"aard",
-                             "vird",
-                             "Zard",
-                             "Zerd",
-                             "\u00feard",
-                             "\u00deard",
-                             "\u00e6ard",
-                             "\u00c6ard"};
+          String[] sortedData = {"aard",
+                                 "vird",
+                                 "Zard",
+                                 "Zerd",
+                                 "\u00feard",
+                                 "\u00deard",
+                                 "\u00e6ard",
+                                 "\u00c6ard"};
 
-      Arrays.sort (data, col);
+          Arrays.sort (data, col);
 
-      System.out.println ("Using " + loc.getDisplayName());
-      for (int i = 0;  i < data.length;  i++) {
-          System.out.println(data[i] + "  :  " + sortedData[i]);
-          if (sortedData[i].compareTo(data[i]) != 0) {
-              errors++;
-          }
-      }//end for
+          System.out.println ("Using " + loc.getDisplayName());
+          for (int i = 0;  i < data.length;  i++) {
+              System.out.println(data[i] + "  :  " + sortedData[i]);
+              if (sortedData[i].compareTo(data[i]) != 0) {
+                  errors++;
+              }
+          }//end for
 
-      if (errors > 0)
-          throw new RuntimeException();
+          if (errors > 0)
+              throw new RuntimeException();
+      } finally {
+          // restore the reserved locale
+          Locale.setDefault(reservedLocale);
+      }
   }//end main
 
 }//end class CollatorTest
--- a/jdk/test/sun/text/resources/Collator/Bug4804273.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/sun/text/resources/Collator/Bug4804273.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,82 +35,89 @@
   /********************************************************
   *********************************************************/
   public static void main (String[] args) {
-      int errors=0;
+      Locale reservedLocale = Locale.getDefault();
+      try {
+        int errors=0;
 
-      Locale loc = new Locale ("sv", "se");   // Swedish
+        Locale loc = new Locale ("sv", "se");   // Swedish
 
-      Locale.setDefault (loc);
-      Collator col = Collator.getInstance ();
+        Locale.setDefault (loc);
+        Collator col = Collator.getInstance ();
 
-      String[] data = {"A",
-                       "Aa",
-                       "Ae",
-                       "B",
-                       "Y",
-                       "U\u0308", // U-umlaut
-                       "Z",
-                       "A\u030a", // A-ring
-                       "A\u0308", // A-umlaut
-                       "\u00c6", // AE ligature
-                       "O\u0308", // O-umlaut
-                       "a\u030b", // a-double-acute
-                       "\u00d8", // O-stroke
-                       "a",
-                       "aa",
-                       "ae",
-                       "b",
-                       "y",
-                       "u\u0308", // u-umlaut
-                       "z",
-                       "A\u030b", // A-double-acute
-                       "a\u030a", // a-ring
-                       "a\u0308", // a-umlaut
-                       "\u00e6", // ae ligature
-                       "o\u0308", // o-umlaut
-                       "\u00f8", // o-stroke
-      };
+        String[] data = {"A",
+                         "Aa",
+                         "Ae",
+                         "B",
+                         "Y",
+                         "U\u0308", // U-umlaut
+                         "Z",
+                         "A\u030a", // A-ring
+                         "A\u0308", // A-umlaut
+                         "\u00c6", // AE ligature
+                         "O\u0308", // O-umlaut
+                         "a\u030b", // a-double-acute
+                         "\u00d8", // O-stroke
+                         "a",
+                         "aa",
+                         "ae",
+                         "b",
+                         "y",
+                         "u\u0308", // u-umlaut
+                         "z",
+                         "A\u030b", // A-double-acute
+                         "a\u030a", // a-ring
+                         "a\u0308", // a-umlaut
+                         "\u00e6", // ae ligature
+                         "o\u0308", // o-umlaut
+                         "\u00f8", // o-stroke
+        };
 
 
-      String[] sortedData = {"a",
-                             "A",
-                             "aa",
-                             "Aa",
-                             "ae",
-                             "Ae",
-                             "b",
-                             "B",
-                             "y",
-                             "Y",
-                             "u\u0308", // o-umlaut
-                             "U\u0308", // o-umlaut
-                             "z",
-                             "Z",
-                             "a\u030a", // a-ring
-                             "A\u030a", // A-ring
-                             "a\u0308", // a-umlaut
-                             "A\u0308", // A-umlaut
-                             "a\u030b", // a-double-acute
-                             "A\u030b", // A-double-acute
-                             "\u00e6", // ae ligature
-                             "\u00c6", // AE ligature
-                             "o\u0308", // o-umlaut
-                             "O\u0308", // O-umlaut
-                             "\u00f8", // o-stroke
-                             "\u00d8", // O-stroke
-      };
+        String[] sortedData = {"a",
+                               "A",
+                               "aa",
+                               "Aa",
+                               "ae",
+                               "Ae",
+                               "b",
+                               "B",
+                               "y",
+                               "Y",
+                               "u\u0308", // o-umlaut
+                               "U\u0308", // o-umlaut
+                               "z",
+                               "Z",
+                               "a\u030a", // a-ring
+                               "A\u030a", // A-ring
+                               "a\u0308", // a-umlaut
+                               "A\u0308", // A-umlaut
+                               "a\u030b", // a-double-acute
+                               "A\u030b", // A-double-acute
+                               "\u00e6", // ae ligature
+                               "\u00c6", // AE ligature
+                               "o\u0308", // o-umlaut
+                               "O\u0308", // O-umlaut
+                               "\u00f8", // o-stroke
+                               "\u00d8", // O-stroke
+        };
 
-      Arrays.sort (data, col);
+        Arrays.sort (data, col);
 
-      System.out.println ("Using " + loc.getDisplayName());
-      for (int i = 0;  i < data.length;  i++) {
-          System.out.println(data[i] + "  :  " + sortedData[i]);
-          if (sortedData[i].compareTo(data[i]) != 0) {
-              errors++;
-          }
-      }//end for
+        System.out.println ("Using " + loc.getDisplayName());
+        for (int i = 0;  i < data.length;  i++) {
+            System.out.println(data[i] + "  :  " + sortedData[i]);
+            if (sortedData[i].compareTo(data[i]) != 0) {
+                errors++;
+            }
+        }//end for
 
-      if (errors > 0)
-          throw new RuntimeException("There are " + errors + " words sorted incorrectly!");
+        if (errors > 0)
+            throw new RuntimeException("There are " + errors +
+                        " words sorted incorrectly!");
+      } finally {
+          // restore the reserved locale
+          Locale.setDefault(reservedLocale);
+      }
   }//end main
 
 }//end class CollatorTest
--- a/jdk/test/sun/text/resources/Collator/Bug4848897.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/sun/text/resources/Collator/Bug4848897.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,39 +35,44 @@
   /********************************************************
   *********************************************************/
   public static void main (String[] args) {
-
-      int errors=0;
-      Locale loc = new Locale ("no", "NO");   // Norwegian
-
-      Locale.setDefault (loc);
-      Collator col = Collator.getInstance ();
+      Locale reservedLocale = Locale.getDefault();
+      try {
+          int errors=0;
+          Locale loc = new Locale ("no", "NO");   // Norwegian
 
-      String[] data = {"wird",
-                       "vird",
-                       "verd",
-                       "werd",
-                       "vard",
-                       "ward"};
+          Locale.setDefault (loc);
+          Collator col = Collator.getInstance ();
+
+          String[] data = {"wird",
+                           "vird",
+                           "verd",
+                           "werd",
+                           "vard",
+                           "ward"};
 
-      String[] sortedData = {"vard",
-                             "verd",
-                             "vird",
-                             "ward",
-                             "werd",
-                             "wird"};
+          String[] sortedData = {"vard",
+                                 "verd",
+                                 "vird",
+                                 "ward",
+                                 "werd",
+                                 "wird"};
 
-      Arrays.sort (data, col);
+          Arrays.sort (data, col);
 
-      System.out.println ("Using " + loc.getDisplayName());
-      for (int i = 0;  i < data.length;  i++) {
-          System.out.println(data[i] + "  :  " + sortedData[i]);
-          if (sortedData[i].compareTo(data[i]) != 0) {
-              errors++;
-          }
-      }//end for
+          System.out.println ("Using " + loc.getDisplayName());
+          for (int i = 0;  i < data.length;  i++) {
+              System.out.println(data[i] + "  :  " + sortedData[i]);
+              if (sortedData[i].compareTo(data[i]) != 0) {
+                  errors++;
+              }
+          }//end for
 
-      if (errors > 0)
-          throw new RuntimeException();
-  }//end main
+          if (errors > 0)
+              throw new RuntimeException();
+      } finally {
+          // restore the reserved locale
+          Locale.setDefault(reservedLocale);
+      }
+  } // end main
 
 }//end class CollatorTest
--- a/jdk/test/sun/text/resources/Format/Bug4651568.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/sun/text/resources/Format/Bug4651568.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,23 +34,29 @@
 public class Bug4651568 {
 
     public static void main (String argv[] )  {
-        String expectedCurrencyPattern = "\u00A4 #.##0,00";
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            String expectedCurrencyPattern = "\u00A4 #.##0,00";
 
-        Locale locale = new Locale ("pt", "BR");
-        Locale.setDefault(locale);
+            Locale locale = new Locale ("pt", "BR");
+            Locale.setDefault(locale);
 
-        DecimalFormat formatter =
-            (DecimalFormat) NumberFormat.getCurrencyInstance(locale);
+            DecimalFormat formatter =
+                (DecimalFormat) NumberFormat.getCurrencyInstance(locale);
 
-        if (formatter.toLocalizedPattern().equals(expectedCurrencyPattern))
-{
-            System.out.println ("Passed.");
-        } else {
-             System.out.println ("Failed Currency pattern." +
-                    "  Expected:  " + expectedCurrencyPattern +
-                    "  Received:  " + formatter.toLocalizedPattern() );
-             throw new RuntimeException();
+            if (formatter.toLocalizedPattern().equals(
+                        expectedCurrencyPattern)) {
+                System.out.println ("Passed.");
+            } else {
+                 System.out.println ("Failed Currency pattern." +
+                        "  Expected:  " + expectedCurrencyPattern +
+                        "  Received:  " + formatter.toLocalizedPattern() );
+                 throw new RuntimeException();
 
- }
+            }
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
+        }
     }
 }
--- a/jdk/test/sun/util/resources/Locale/Bug4965260.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/sun/util/resources/Locale/Bug4965260.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,49 +30,55 @@
 
 public class Bug4965260  {
 
-  // Define supported locales
-  static Locale[] locales2Test = new Locale[] {
-    new Locale("de"),
-    new Locale("es"),
-    new Locale("fr"),
-    new Locale("it"),
-    new Locale("sv")
-  };
+    // Define supported locales
+    static Locale[] locales2Test = new Locale[] {
+        new Locale("de"),
+        new Locale("es"),
+        new Locale("fr"),
+        new Locale("it"),
+        new Locale("sv")
+    };
 
-  static String[] expectedNames = new String[] {
-    "Niederl\u00e4ndisch",
-    "neerland\u00e9s",
-    "n\u00e9erlandais",
-    "neerlandese",
-    "nederl\u00e4ndska"
-  };
+    static String[] expectedNames = new String[] {
+        "Niederl\u00e4ndisch",
+        "neerland\u00e9s",
+        "n\u00e9erlandais",
+        "neerlandese",
+        "nederl\u00e4ndska"
+    };
 
-  public static void main(String[] args) throws Exception {
-    Locale.setDefault(Locale.ENGLISH);
-    if (locales2Test.length != expectedNames.length) {
-      throw new Exception("\nData sizes does not match!\n");
-    }
+    public static void main(String[] args) throws Exception {
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            Locale.setDefault(Locale.ENGLISH);
+            if (locales2Test.length != expectedNames.length) {
+                throw new Exception("\nData sizes does not match!\n");
+            }
 
-    StringBuffer message = new StringBuffer("");
-    Locale dutch = new Locale("nl", "BE");
-    String current;
-    for (int i = 0; i < locales2Test.length; i++) {
-      Locale locale = locales2Test[i];
-      current = dutch.getDisplayLanguage(locale);
-      if (!current.equals(expectedNames[i])) {
-        message.append("[");
-        message.append(locale.getDisplayLanguage());
-        message.append("] ");
-        message.append("Language name is ");
-        message.append(current);
-        message.append(" should be ");
-        message.append(expectedNames[i]);
-        message.append("\n");
-      }
+            StringBuffer message = new StringBuffer("");
+            Locale dutch = new Locale("nl", "BE");
+            String current;
+            for (int i = 0; i < locales2Test.length; i++) {
+                Locale locale = locales2Test[i];
+                current = dutch.getDisplayLanguage(locale);
+                if (!current.equals(expectedNames[i])) {
+                    message.append("[");
+                    message.append(locale.getDisplayLanguage());
+                    message.append("] ");
+                    message.append("Language name is ");
+                    message.append(current);
+                    message.append(" should be ");
+                    message.append(expectedNames[i]);
+                    message.append("\n");
+                }
+            }
+
+            if (message.length() >0) {
+                throw new Exception("\n" + message.toString());
+            }
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
+        }
     }
-
-    if (message.length() >0) {
-      throw new Exception("\n" + message.toString());
-    }
-  }
 }
--- a/jdk/test/sun/util/resources/TimeZone/Bug4640234.java	Thu Jul 28 13:34:31 2011 -0700
+++ b/jdk/test/sun/util/resources/TimeZone/Bug4640234.java	Fri Jul 29 02:50:58 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,11 +24,11 @@
 /**
  * @test
  * @bug 4640234 4946057 4938151 4873691 5023181
- * @summary Verifies the translation of time zone names, this test will catch presence
- *          of country name for english and selected locales for all ISO country
- *          codes.
- *          The test program also displays which timezone, country and language names
- *          are not translated
+ * @summary Verifies the translation of time zone names, this test will catch
+ *          presence of country name for english and selected locales for all
+ *          ISO country codes.
+ *          The test program also displays which timezone, country and
+ *          language names are not translated
  */
 
 
@@ -51,230 +51,242 @@
 
 
 public class Bug4640234  {
-  static SimpleDateFormat sdfEn = new SimpleDateFormat("zzzz", Locale.US);
-  static SimpleDateFormat sdfEnShort = new SimpleDateFormat("z", Locale.US);
-  static Locale locEn = Locale.ENGLISH;
+    static SimpleDateFormat sdfEn = new SimpleDateFormat("zzzz", Locale.US);
+    static SimpleDateFormat sdfEnShort = new SimpleDateFormat("z", Locale.US);
+    static Locale locEn = Locale.ENGLISH;
 
-  static SimpleDateFormat sdfLoc;
-  static SimpleDateFormat sdfLocShort;
-  static Date date = new Date();
+    static SimpleDateFormat sdfLoc;
+    static SimpleDateFormat sdfLocShort;
+    static Date date = new Date();
 
-  // Define supported locales
-  static Locale[] locales2Test = new Locale[] {
-    new Locale("de"),
-    new Locale("es"),
-    new Locale("fr"),
-    new Locale("it"),
-    new Locale("ja"),
-    new Locale("ko"),
-    new Locale("sv"),
-    new Locale("zh", "CN"),
-    new Locale("zh", "TW")
-  };
+    // Define supported locales
+    static Locale[] locales2Test = new Locale[] {
+        new Locale("de"),
+        new Locale("es"),
+        new Locale("fr"),
+        new Locale("it"),
+        new Locale("ja"),
+        new Locale("ko"),
+        new Locale("sv"),
+        new Locale("zh", "CN"),
+        new Locale("zh", "TW")
+    };
 
-  public static void main(String[] args) throws Exception {
-    Locale.setDefault(Locale.ENGLISH);
+    public static void main(String[] args) throws Exception {
+        Locale reservedLocale = Locale.getDefault();
+        try {
+            Locale.setDefault(Locale.ENGLISH);
 
-    StringBuffer errors = new StringBuffer("");
-    StringBuffer warnings = new StringBuffer("");
+            StringBuffer errors = new StringBuffer("");
+            StringBuffer warnings = new StringBuffer("");
 
-    String[] timezones = TimeZone.getAvailableIDs();
-    String[] countries = locEn.getISOCountries();
-    String[] languages = locEn.getISOLanguages();
+            String[] timezones = TimeZone.getAvailableIDs();
+            String[] countries = locEn.getISOCountries();
+            String[] languages = locEn.getISOLanguages();
 
-    ResourceBundle resEn = ResourceBundle.getBundle("sun.util.resources.LocaleNames", locEn);
-    Map<String, String> countryMapEn = getList(resEn, true);
-    Map<String, String> languageMapEn = getList(resEn, false);
+            ResourceBundle resEn = ResourceBundle.getBundle(
+                    "sun.util.resources.LocaleNames", locEn);
+            Map<String, String> countryMapEn = getList(resEn, true);
+            Map<String, String> languageMapEn = getList(resEn, false);
 
-    ResourceBundle resLoc;
-    Map<String, String> countryMap;
-    Map<String, String> languageMap;
+            ResourceBundle resLoc;
+            Map<String, String> countryMap;
+            Map<String, String> languageMap;
 
-    for (Locale locale : locales2Test) {
-      resLoc = ResourceBundle.getBundle("sun.util.resources.LocaleNames", locale);
+            for (Locale locale : locales2Test) {
+                resLoc = ResourceBundle.getBundle(
+                    "sun.util.resources.LocaleNames", locale);
 
-      sdfLoc = new SimpleDateFormat("zzzz", locale);
-      sdfLocShort = new SimpleDateFormat("z", locale);
+                sdfLoc = new SimpleDateFormat("zzzz", locale);
+                sdfLocShort = new SimpleDateFormat("z", locale);
 
-      for (String timezone : timezones) {
-        if (isTZIgnored(timezone)) {
-          continue;
-        }
-        warnings.append(testTZ(timezone, locale));
-      }
+                for (String timezone : timezones) {
+                    if (isTZIgnored(timezone)) {
+                        continue;
+                    }
+                    warnings.append(testTZ(timezone, locale));
+                }
+
+                countryMap = getList(resLoc, true);
 
-      countryMap = getList(resLoc, true);
+                for (String country : countries) {
+                    String[] result = testEntry(country,
+                        countryMapEn,
+                        countryMap,
+                        locale,
+                        "ERROR: {0} country name for country code: {1} not found!\n",
+                        "WARNING: {0} country name for country code: {1} not localized!\n"
+                    );
+                    if (warnings.indexOf(result[0]) == -1) {
+                        warnings.append(result[0]);
+                    }
+                    if (errors.indexOf(result[1]) == -1) {
+                        errors.append(result[1]);
+                    }
+                }
 
-      for (String country : countries) {
-        String[] result = testEntry(country,
-          countryMapEn,
-          countryMap,
-          locale,
-          "ERROR: {0} country name for country code: {1} not found!\n",
-          "WARNING: {0} country name for country code: {1} not localized!\n"
-        );
-        if (warnings.indexOf(result[0]) == -1) {
-          warnings.append(result[0]);
-        }
-        if (errors.indexOf(result[1]) == -1) {
-          errors.append(result[1]);
+                languageMap = getList(resLoc, false);
+                for (String language : languages) {
+                    String[] result = testEntry(language,
+                        languageMapEn,
+                        languageMap,
+                        locale,
+                        "ERROR: {0} language name for language code: {1} not found!\n",
+                        "WARNING: {0} language name for language code: {1} not localized!\n");
+                    if (warnings.indexOf(result[0]) == -1) {
+                        warnings.append(result[0]);
+                    }
+                    if (errors.indexOf(result[1]) == -1) {
+                        errors.append(result[1]);
+                    }
+                }
+            }
+
+            StringBuffer message = new StringBuffer("");
+            if (!"".equals(errors.toString())) {
+                message.append("Test failed! ");
+                message.append("ERROR: some keys are missing! ");
+            }
+
+            if ("".equals(message.toString())) {
+                System.out.println("\nTest passed");
+                System.out.println(warnings.toString());
+            } else {
+                System.out.println("\nTest failed!");
+                System.out.println(errors.toString());
+                System.out.println(warnings.toString());
+                throw new Exception("\n" + message);
+            }
+        } finally {
+            // restore the reserved locale
+            Locale.setDefault(reservedLocale);
         }
-      }
-
-      languageMap = getList(resLoc, false);
-      for (String language : languages) {
-        String[] result = testEntry(language,
-          languageMapEn,
-          languageMap,
-          locale,
-          "ERROR: {0} language name for language code: {1} not found!\n",
-          "WARNING: {0} language name for language code: {1} not localized!\n");
-        if (warnings.indexOf(result[0]) == -1) {
-          warnings.append(result[0]);
-        }
-        if (errors.indexOf(result[1]) == -1) {
-          errors.append(result[1]);
-        }
-      }
-    }
-
-    StringBuffer message = new StringBuffer("");
-    if (!"".equals(errors.toString())) {
-      message.append("Test failed! ");
-      message.append("ERROR: some keys are missing! ");
     }
 
-    if ("".equals(message.toString())) {
-      System.out.println("\nTest passed");
-      System.out.println(warnings.toString());
-    } else {
-      System.out.println("\nTest failed!");
-      System.out.println(errors.toString());
-      System.out.println(warnings.toString());
-      throw new Exception("\n" + message);
-    }
-  }
+    /**
+    * Compares the english timezone name and timezone name in specified locale
+    * @param timeZoneName - name of the timezone to compare
+    * @param locale - locale to test against english
+    * @return empty string when passed, descriptive error message in other cases
+    */
+    private static String testTZ(String timeZoneName, Locale locale) {
+        StringBuffer timeZoneResult = new StringBuffer("");
+        TimeZone tz = TimeZone.getTimeZone(timeZoneName);
+        sdfEn.setTimeZone(tz);
+        sdfEnShort.setTimeZone(tz);
+        sdfLoc.setTimeZone(tz);
+        sdfLocShort.setTimeZone(tz);
+
+        String en, enShort, loc, locShort;
+        en = sdfEn.format(date);
+        enShort = sdfEnShort.format(date);
+        loc = sdfLoc.format(date);
+        locShort = sdfLocShort.format(date);
+
+        String displayLanguage = locale.getDisplayLanguage();
+        String displayCountry = locale.getDisplayCountry();
 
-  /**
-  * Compares the english timezone name and timezone name in specified locale
-  * @param timeZoneName - name of the timezone to compare
-  * @param locale - locale to test against english
-  * @return empty string when passed, descriptive error message in other cases
-  */
-  private static String testTZ(String timeZoneName, Locale locale) {
-    StringBuffer timeZoneResult = new StringBuffer("");
-    TimeZone tz = TimeZone.getTimeZone(timeZoneName);
-    sdfEn.setTimeZone(tz);
-    sdfEnShort.setTimeZone(tz);
-    sdfLoc.setTimeZone(tz);
-    sdfLocShort.setTimeZone(tz);
+        if (loc.equals(en)) {
+            timeZoneResult.append("[");
+            timeZoneResult.append(displayLanguage);
+            if (!"".equals(displayCountry)) {
+                timeZoneResult.append(" ");
+                timeZoneResult.append(displayCountry);
+            }
+            timeZoneResult.append("] timezone \"");
+            timeZoneResult.append(timeZoneName);
+            timeZoneResult.append("\" long name \"" + en);
+            timeZoneResult.append("\" not localized!\n");
+        }
 
-    String en, enShort, loc, locShort;
-    en = sdfEn.format(date);
-    enShort = sdfEnShort.format(date);
-    loc = sdfLoc.format(date);
-    locShort = sdfLocShort.format(date);
-
-    String displayLanguage = locale.getDisplayLanguage();
-    String displayCountry = locale.getDisplayCountry();
-
-    if (loc.equals(en)) {
-      timeZoneResult.append("[");
-      timeZoneResult.append(displayLanguage);
-      if (!"".equals(displayCountry)) {
-        timeZoneResult.append(" ");
-        timeZoneResult.append(displayCountry);
-      }
-      timeZoneResult.append("] timezone \"");
-      timeZoneResult.append(timeZoneName);
-      timeZoneResult.append("\" long name \"" + en);
-      timeZoneResult.append("\" not localized!\n");
+        if (!locShort.equals(enShort)) {
+            timeZoneResult.append("[");
+            timeZoneResult.append(displayLanguage);
+            if (!"".equals(displayCountry)) {
+                timeZoneResult.append(" ");
+                timeZoneResult.append(displayCountry);
+            }
+            timeZoneResult.append("] timezone \"");
+            timeZoneResult.append(timeZoneName);
+            timeZoneResult.append("\" short name \"" + enShort);
+            timeZoneResult.append("\" is localized \"");
+            timeZoneResult.append(locShort);
+            timeZoneResult.append("\"!\n");
+        }
+        return timeZoneResult.toString();
     }
 
-    if (!locShort.equals(enShort)) {
-      timeZoneResult.append("[");
-      timeZoneResult.append(displayLanguage);
-      if (!"".equals(displayCountry)) {
-        timeZoneResult.append(" ");
-        timeZoneResult.append(displayCountry);
-      }
-      timeZoneResult.append("] timezone \"");
-      timeZoneResult.append(timeZoneName);
-      timeZoneResult.append("\" short name \"" + enShort);
-      timeZoneResult.append("\" is localized \"");
-      timeZoneResult.append(locShort);
-      timeZoneResult.append("\"!\n");
-    }
-    return timeZoneResult.toString();
-  }
+    /**
+    * Verifies whether the name for ISOCode is localized.
+    * @param ISOCode - ISO country/language code for country/language name
+    *      to test
+    * @param entriesEn - array of english country/language names
+    * @param entriesLoc - array of localized country/language names for
+    *      specified locale
+    * @param locale - locale to test against english
+    * @param notFoundMessage - message in form ready for MessageFormat,
+    *      {0} will be human readable language name, {1} will be ISOCode.
+    * @param notLocalizedMessage - message in for ready for MessageFormat,
+    *      same formatting like for notFountMessage
+    * @return array of two empty strings when passed, descriptive error message
+    *      in other cases, [0] - warnings for not localized, [1] - errors for
+    *      missing keys.
+    */
+    private static String[] testEntry(String ISOCode,
+                Map<String, String> entriesEn,
+                Map<String, String> entriesLoc,
+                Locale locale,
+                String notFoundMessage,
+                String notLocalizedMessage) {
+        String nameEn = null;
+        String nameLoc = null;
 
-  /**
-  * Verifies whether the name for ISOCode is localized.
-  * @param ISOCode - ISO country/language code for country/language name to test
-  * @param entriesEn - array of english country/language names
-  * @param entriesLoc - array of localized country/language names for specified locale
-  * @param locale - locale to test against english
-  * @param notFoundMessage - message in form ready for MessageFormat, {0} will be human readable
-  *                          language name, {1} will be ISOCode.
-  * @param notLocalizedMessage - message in for ready for MessageFormat, same formatting like
-  *                              for notFountMessage
-  * @return array of two empty strings when passed, descriptive error message in
-  *         other cases, [0] - warnings for not localized, [1] - errors for missing keys.
-  */
-  private static String[] testEntry(String ISOCode,
-                                    Map<String, String> entriesEn,
-                                    Map<String, String> entriesLoc,
-                                    Locale locale,
-                                    String notFoundMessage,
-                                    String notLocalizedMessage) {
-    String nameEn = null;
-    String nameLoc = null;
+        for (String key: entriesEn.keySet()) {
+            if (ISOCode.equalsIgnoreCase(key)) {
+                nameEn = entriesEn.get(key);
+                break;
+            }
+        }
+
+        for (String key: entriesLoc.keySet()) {
+            if (ISOCode.equalsIgnoreCase(key)) {
+                nameLoc = entriesLoc.get(key);
+                break;
+            }
+        }
 
-    for (String key: entriesEn.keySet()) {
-      if (ISOCode.equalsIgnoreCase(key)) {
-        nameEn = entriesEn.get(key);
-        break;
-      }
+        if (nameEn == null) {
+            // We should not get here but test is a MUST have
+            return new String[] {"", MessageFormat.format(notFoundMessage,
+                new String[] {"English", ISOCode})};
+        }
+
+        if (nameLoc == null) {
+            return new String[] {"", MessageFormat.format(notFoundMessage,
+                new String[] {locale.getDisplayName(), ISOCode})};
+        }
+
+        if (nameEn.equals(nameLoc)) {
+            return new String[] {MessageFormat.format(notLocalizedMessage,
+                new String[] {locale.getDisplayName(), ISOCode}), ""};
+        }
+
+        return new String[] {"", ""};
     }
 
-    for (String key: entriesLoc.keySet()) {
-      if (ISOCode.equalsIgnoreCase(key)) {
-        nameLoc = entriesLoc.get(key);
-        break;
-      }
-    }
-
-    if (nameEn == null) {
-      // We should not get here but test is a MUST have
-      return new String[] {"", MessageFormat.format(notFoundMessage,
-        new String[] {"English", ISOCode})};
-    }
-
-    if (nameLoc == null) {
-      return new String[] {"", MessageFormat.format(notFoundMessage,
-        new String[] {locale.getDisplayName(), ISOCode})};
+    private static boolean isTZIgnored(String TZName) {
+        if (TZName.startsWith("Etc/GMT") ||
+                TZName.indexOf("Riyadh8") != -1 ||
+                TZName.equals("GMT0") ||
+                TZName.equals("MET")
+                ) {
+            return true;
+        }
+        return false;
     }
 
-    if (nameEn.equals(nameLoc)) {
-      return new String[] {MessageFormat.format(notLocalizedMessage,
-        new String[] {locale.getDisplayName(), ISOCode}), ""};
-    }
-
-    return new String[] {"", ""};
-  }
-
-  private static boolean isTZIgnored(String TZName) {
-    if (TZName.startsWith("Etc/GMT") ||
-        TZName.indexOf("Riyadh8") != -1 ||
-        TZName.equals("GMT0") ||
-        TZName.equals("MET")
-        ) {
-      return true;
-    }
-    return false;
-  }
-
-    private static Map<String, String> getList(ResourceBundle rs, Boolean getCountryList) {
+    private static Map<String, String> getList(
+            ResourceBundle rs, Boolean getCountryList) {
         char beginChar = 'a';
         char endChar = 'z';
         if (getCountryList) {