From 7e21a1417286d6f1181443ac29c99263c3747332 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sat, 8 Mar 2014 16:46:59 +0000 Subject: [PATCH] Adjust for JDK 8 where an empty locale is added to the array returned by DateFormat.getAvailableLocales() git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1575563 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/ss/util/DateFormatConverter.java | 4 ++++ .../org/apache/poi/ss/util/TestDateFormatConverter.java | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/java/org/apache/poi/ss/util/DateFormatConverter.java b/src/java/org/apache/poi/ss/util/DateFormatConverter.java index 316d1ed7b..bca998e80 100644 --- a/src/java/org/apache/poi/ss/util/DateFormatConverter.java +++ b/src/java/org/apache/poi/ss/util/DateFormatConverter.java @@ -93,6 +93,7 @@ public class DateFormatConverter { return result.toArray(new String[0]); } + @Override public String toString() { StringBuilder result = new StringBuilder(); @@ -323,6 +324,9 @@ public class DateFormatConverter { result.put( "in", "[$-0421]" ); result.put( "iw", "[$-40D]" ); + // JDK 8 adds an empty locale-string, see also https://issues.apache.org/jira/browse/LANG-941 + result.put( "", "[$-0409]" ); + return result; } diff --git a/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java b/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java index e4b7c3892..95042e50f 100644 --- a/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java +++ b/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java @@ -137,5 +137,11 @@ public final class TestDateFormatConverter extends TestCase { outputLocaleDataFormats(date, false, true, DateFormat.LONG, "Long" ); outputLocaleDataFormats(date, false, true, DateFormat.FULL, "Full" ); } + + public void testJDK8EmptyLocale() { + // JDK 8 seems to add an empty locale-string to the list returned via DateFormat.getAvailableLocales() + // therefore we now cater for this special locale as well + DateFormatConverter.getPrefixForLocale(new Locale("")); + } }