http://docs.oracle.com/javase/7/docs/api/java/util/Locale.html#getDisplayName()
==
depending on which fields are specified in the locale. If the language,
sacript, country, and variant fields are all empty, this function
returns the empty string.
==
I'd really like to know what locale definition is returning empty for
all *4* of those values, which then causes getDisplayName() to return
empty as well. That seems to actually be the WTF about this.
ps: note the typo in my cut and paste; that's in the actual documentation.
On 04/29/2015 01:10 AM, adri...@apache.org wrote:
Author: adrianc
Date: Wed Apr 29 06:10:01 2015
New Revision: 1676674
URL: http://svn.apache.org/r1676674
Log:
Fixed a bug in UtilMisc.java where the List returned by the availableLocales()
method included an empty Locale - causing errors in FreeMarker templates.
https://issues.apache.org/jira/browse/OFBIZ-6309
Added:
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilMiscTests.java
Modified:
ofbiz/trunk/framework/base/build.xml
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java
ofbiz/trunk/framework/base/testdef/basetests.xml
Modified: ofbiz/trunk/framework/base/build.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/build.xml?rev=1676674&r1=1676673&r2=1676674&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/build.xml (original)
+++ ofbiz/trunk/framework/base/build.xml Wed Apr 29 06:10:01 2015
@@ -41,6 +41,7 @@ under the License.
<file name="org/ofbiz/base/lang/test/ComparableRangeTests.java"/>
<file name="org/ofbiz/base/util/test/IndentingWriterTests.java"/>
<file name="org/ofbiz/base/util/test/ObjectTypeTests.java"/>
+ <file name="org/ofbiz/base/util/test/UtilMiscTests.java"/>
<file name="org/ofbiz/base/util/test/UtilObjectTests.java"/>
<file
name="org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java"/>
<file
name="org/ofbiz/base/util/collections/test/FlexibleMapAccessorTests.java"/>
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java?rev=1676674&r1=1676673&r2=1676674&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java Wed Apr 29
06:10:01 2015
@@ -746,7 +746,10 @@ public class UtilMisc {
} else {
Locale[] locales = Locale.getAvailableLocales();
for (int i = 0; i < locales.length && locales[i] != null;
i++) {
- localeMap.put(locales[i].getDisplayName(), locales[i]);
+ String displayName = locales[i].getDisplayName();
+ if (!displayName.isEmpty()) {
+ localeMap.put(displayName, locales[i]);
+ }
}
}
return Collections.unmodifiableList(new
ArrayList<Locale>(localeMap.values()));
Added:
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilMiscTests.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilMiscTests.java?rev=1676674&view=auto
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilMiscTests.java
(added)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilMiscTests.java
Wed Apr 29 06:10:01 2015
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
*******************************************************************************/
+package org.ofbiz.base.util.test;
+
+import java.util.List;
+import java.util.Locale;
+
+import org.ofbiz.base.test.GenericTestCaseBase;
+import org.ofbiz.base.util.UtilMisc;
+
+public class UtilMiscTests extends GenericTestCaseBase {
+
+ public UtilMiscTests(String name) {
+ super(name);
+ }
+
+ public void testLocales() throws Exception {
+ List<Locale> availableLocales = UtilMisc.availableLocales();
+ for (Locale availableLocale : availableLocales) {
+ if (availableLocale.getDisplayName().isEmpty()) {
+ fail("Locale.getDisplayName() is empty");
+ }
+ }
+ }
+}
Modified: ofbiz/trunk/framework/base/testdef/basetests.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/testdef/basetests.xml?rev=1676674&r1=1676673&r2=1676674&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/testdef/basetests.xml (original)
+++ ofbiz/trunk/framework/base/testdef/basetests.xml Wed Apr 29 06:10:01 2015
@@ -27,6 +27,7 @@
<junit-test-suite
class-name="org.ofbiz.base.util.test.IndentingWriterTests"/>
<junit-test-suite
class-name="org.ofbiz.base.util.test.ObjectTypeTests"/>
<!--junit-test-suite
class-name="org.ofbiz.base.util.test.ReferenceCleanerTests"/-->
+ <junit-test-suite class-name="org.ofbiz.base.util.test.UtilMiscTests"/>
<junit-test-suite
class-name="org.ofbiz.base.util.test.UtilObjectTests"/>
<junit-test-suite
class-name="org.ofbiz.base.util.test.StringUtilTests"/>
<junit-test-suite
class-name="org.ofbiz.base.util.test.UtilHttpTests"/>