Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-11484 - Fix LocaleTypeDescriptor to handle Locale.ROOT #1793

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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