Skip to content

Commit

Permalink
HHH-11484 - Fix LocaleTypeDescriptor to handle Locale.ROOT
Browse files Browse the repository at this point in the history
(cherry picked from commit 3c2939f)
  • Loading branch information
benoit-lateltin authored and gbadner committed May 16, 2017
1 parent 8433260 commit d94dda3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Expand Up @@ -13,7 +13,7 @@

/**
* Descriptor for {@link Locale} handling.
*
*
* @author Steve Ebersole
*/
public class LocaleTypeDescriptor extends AbstractTypeDescriptor<Locale> {
Expand Down Expand Up @@ -43,10 +43,14 @@ public String toString(Locale value) {
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();
Expand Down
Expand Up @@ -32,6 +32,8 @@ public void testConversionFromString() {
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) {
Expand Down

0 comments on commit d94dda3

Please sign in to comment.