From b39fdbf1f8bfaf0e717deb5b8530bbe52534f665 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Sat, 27 Apr 2013 11:54:09 +0300 Subject: [PATCH] Fix string to locale conversion The original implementation didn't care about leading underscores. StringTokenizer skips leading separators which is actually wrong. new Locale("", "XX").toString() produces "_XX" which can't be converted back to the same locale with the original implementation. --- .../hibernate/type/descriptor/java/LocaleTypeDescriptor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleTypeDescriptor.java index 646662ac00..e12f28312f 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleTypeDescriptor.java @@ -60,8 +60,8 @@ public class LocaleTypeDescriptor extends AbstractTypeDescriptor { public Locale fromString(String string) { StringTokenizer tokens = new StringTokenizer( string, "_" ); - String language = tokens.hasMoreTokens() ? tokens.nextToken() : ""; - String country = tokens.hasMoreTokens() ? tokens.nextToken() : ""; + String language = tokens.hasMoreTokens() && string.charAt(0) != '_' ? tokens.nextToken() : ""; + String country = tokens.hasMoreTokens() && string.charAt(string.indexOf(language) + language.length() + 1) != '_' ? tokens.nextToken() : ""; // Need to account for allowable '_' within the variant String variant = ""; String sep = "";