jdk/test/sun/text/resources/Collator/Bug4848897.java
changeset 10138 b7572da25d15
parent 5506 202f599c92aa
--- 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