@@ -36,25 +36,31 @@ public void jsonObjectByLocaleBean() {
3636
3737 MyLocaleBean myLocaleBean = new MyLocaleBean ();
3838
39- /**
40- * This is just the control case which happens when the locale.ROOT
41- * lowercasing behavior is the same as the current locale.
42- */
43- Locale .setDefault (new Locale ("en" ));
44- JSONObject jsonen = new JSONObject (myLocaleBean );
45- assertEquals ("expected size 2, found: " +jsonen .length (), 2 , jsonen .length ());
46- assertEquals ("expected jsonen[i] == beanI" , "beanI" , jsonen .getString ("i" ));
47- assertEquals ("expected jsonen[id] == beanId" , "beanId" , jsonen .getString ("id" ));
48-
49- /**
50- * Without the JSON-Java change, these keys would be stored internally as
51- * starting with the letter, 'ı' (dotless i), since the lowercasing of
52- * the getI and getId keys would be specific to the Turkish locale.
53- */
54- Locale .setDefault (new Locale ("tr" ));
55- JSONObject jsontr = new JSONObject (myLocaleBean );
56- assertEquals ("expected size 2, found: " +jsontr .length (), 2 , jsontr .length ());
57- assertEquals ("expected jsontr[i] == beanI" , "beanI" , jsontr .getString ("i" ));
58- assertEquals ("expected jsontr[id] == beanId" , "beanId" , jsontr .getString ("id" ));
39+ // save and restore the current default locale, to avoid any side effects on other executions in the same JVM
40+ Locale defaultLocale = Locale .getDefault ();
41+ try {
42+ /**
43+ * This is just the control case which happens when the locale.ROOT
44+ * lowercasing behavior is the same as the current locale.
45+ */
46+ Locale .setDefault (new Locale ("en" ));
47+ JSONObject jsonen = new JSONObject (myLocaleBean );
48+ assertEquals ("expected size 2, found: " +jsonen .length (), 2 , jsonen .length ());
49+ assertEquals ("expected jsonen[i] == beanI" , "beanI" , jsonen .getString ("i" ));
50+ assertEquals ("expected jsonen[id] == beanId" , "beanId" , jsonen .getString ("id" ));
51+
52+ /**
53+ * Without the JSON-Java change, these keys would be stored internally as
54+ * starting with the letter, 'ı' (dotless i), since the lowercasing of
55+ * the getI and getId keys would be specific to the Turkish locale.
56+ */
57+ Locale .setDefault (new Locale ("tr" ));
58+ JSONObject jsontr = new JSONObject (myLocaleBean );
59+ assertEquals ("expected size 2, found: " +jsontr .length (), 2 , jsontr .length ());
60+ assertEquals ("expected jsontr[i] == beanI" , "beanI" , jsontr .getString ("i" ));
61+ assertEquals ("expected jsontr[id] == beanId" , "beanId" , jsontr .getString ("id" ));
62+ } finally {
63+ Locale .setDefault (defaultLocale );
64+ }
5965 }
6066}
0 commit comments