From c99a4a3ee24758ae6e2271752d91b58c116e81e9 Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Fri, 3 Jan 2014 09:43:49 +0000 Subject: [PATCH] LANG-941: Test failure in LocaleUtilsTest when building with JDK 8 - make problem more explicit by checking for empty strings git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1555040 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/java/org/apache/commons/lang3/LocaleUtils.java | 3 +++ src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/org/apache/commons/lang3/LocaleUtils.java b/src/main/java/org/apache/commons/lang3/LocaleUtils.java index da1a5cc6a..166d0d225 100644 --- a/src/main/java/org/apache/commons/lang3/LocaleUtils.java +++ b/src/main/java/org/apache/commons/lang3/LocaleUtils.java @@ -90,6 +90,9 @@ public class LocaleUtils { if (str == null) { return null; } + if (str.isEmpty()) { + throw new IllegalArgumentException("Cannot create locale from empty string"); + } if (str.contains("#")) { // LANG-879 - Cannot handle Java 7 script & extensions throw new IllegalArgumentException("Invalid locale format: " + str); } diff --git a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java index ae2f22a8c..125abf9bb 100644 --- a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java @@ -137,6 +137,10 @@ public class LocaleUtilsTest { // Valid format but lang doesnt exist, should make instance anyway assertValidToLocale("qq"); + try { + LocaleUtils.toLocale(""); + fail("Should fail if str is empty"); + } catch (final IllegalArgumentException iae) {} try { LocaleUtils.toLocale("Us"); fail("Should fail if not lowercase");