HHH-11484 - Fix LocaleTypeDescriptor to handle Locale.ROOT

This commit is contained in:
Benoit Lateltin 2017-02-13 13:08:51 +01:00 committed by Vlad Mihalcea
parent 3adb0d76be
commit 3c2939f0e5
2 changed files with 8 additions and 2 deletions

View File

@ -43,10 +43,14 @@ public class LocaleTypeDescriptor extends AbstractTypeDescriptor<Locale> {
public Locale fromString(String string) {
// TODO : Ultimately switch to Locale.Builder for this. However, Locale.Builder is Java 7
if ( string == null || string.isEmpty() ) {
if ( string == null ) {
return null;
}
if( string.isEmpty() ) {
return Locale.ROOT;
}
boolean separatorFound = false;
int position = 0;
char[] chars = string.toCharArray();

View File

@ -32,6 +32,8 @@ public class LocaleTypeDescriptorTest extends BaseUnitTestCase {
assertEquals( toLocale( null, "DE", "ch123" ), LocaleTypeDescriptor.INSTANCE.fromString( "_DE_ch123" ) );
assertEquals( toLocale( "de", null, "ch123" ), LocaleTypeDescriptor.INSTANCE.fromString( "de__ch123" ) );
assertEquals( toLocale( "de", "DE", "ch123" ), LocaleTypeDescriptor.INSTANCE.fromString( "de_DE_ch123" ) );
assertEquals( toLocale( "", "", "" ), LocaleTypeDescriptor.INSTANCE.fromString( "" ) );
assertEquals( Locale.ROOT, LocaleTypeDescriptor.INSTANCE.fromString( "" ) );
}
public Locale toLocale(String lang, String region, String variant) {