@@ -282,6 +282,8 @@ public static class Std extends FromStringDeserializer<Object>
282282 // No longer implemented here since 2.12
283283 // public final static int STD_STRING_BUILDER = 13;
284284
285+ protected final static String LOCALE_EXT_MARKER = "_#" ;
286+
285287 protected final int _kind ;
286288
287289 protected Std (Class <?> valueType , int kind ) {
@@ -315,25 +317,7 @@ protected Object _deserialize(String value, DeserializationContext ctxt) throws
315317 // will throw IAE (or its subclass) if malformed
316318 return Pattern .compile (value );
317319 case STD_LOCALE :
318- {
319- int ix = _firstHyphenOrUnderscore (value );
320- if (ix < 0 ) { // single argument
321- return new Locale (value );
322- }
323- String first = value .substring (0 , ix );
324- value = value .substring (ix +1 );
325- ix = _firstHyphenOrUnderscore (value );
326- if (ix < 0 ) { // two pieces
327- return new Locale (first , value );
328- }
329- String second = value .substring (0 , ix );
330- if (!_isScriptOrExtensionPresent (value )) {
331- return new Locale (first , second , value .substring (ix +1 ));
332- } else {
333- // Issue #3259: Support for BCP 47 java.util.Locale Serialization / De-serialization
334- return _deSerializeBCP47Locale (value , ix , first , second );
335- }
336- }
320+ return _deserializeLocale (value , ctxt );
337321 case STD_CHARSET :
338322 return Charset .forName (value );
339323 case STD_TIME_ZONE :
@@ -402,17 +386,41 @@ protected int _firstHyphenOrUnderscore(String str)
402386 return -1 ;
403387 }
404388
389+ private Locale _deserializeLocale (String value , DeserializationContext ctxt )
390+ throws IOException
391+ {
392+ int ix = _firstHyphenOrUnderscore (value );
393+ if (ix < 0 ) { // single argument
394+ return new Locale (value );
395+ }
396+ String first = value .substring (0 , ix );
397+ value = value .substring (ix +1 );
398+ ix = _firstHyphenOrUnderscore (value );
399+ if (ix < 0 ) { // two pieces
400+ return new Locale (first , value );
401+ }
402+ String second = value .substring (0 , ix );
403+ if (!_isScriptOrExtensionPresent (value )) {
404+ return new Locale (first , second , value .substring (ix +1 ));
405+ }
406+ // Issue #3259: Support for BCP 47 java.util.Locale Serialization / De-serialization
407+ return _deSerializeBCP47Locale (value , ix , first , second );
408+ }
409+
410+ private boolean _isScriptOrExtensionPresent (String value ) {
411+ return value .contains (LOCALE_EXT_MARKER );
412+ }
413+
405414 private Locale _deSerializeBCP47Locale (String value , int ix , String first , String second ) {
406415 String third = "" ;
407416 try {
408417 int scriptExpIx = value .indexOf ("_#" );
409- /*
410- * Below condition checks if variant value is present to handle empty variant values such as
411- * en__#Latn_x-ext
412- * _US_#Latn
413- */
414- if (scriptExpIx > 0 && scriptExpIx > ix )
418+ // Below condition checks if variant value is present to handle empty variant values such as
419+ // en__#Latn_x-ext
420+ // _US_#Latn
421+ if (scriptExpIx > 0 && scriptExpIx > ix ) {
415422 third = value .substring (ix + 1 , scriptExpIx );
423+ }
416424 value = value .substring (scriptExpIx + 2 );
417425
418426 if (value .indexOf ('_' ) < 0 && value .indexOf ('-' ) < 0 ) {
@@ -436,10 +444,6 @@ private Locale _deSerializeBCP47Locale(String value, int ix, String first, Strin
436444 return new Locale (first , second , third );
437445 }
438446 }
439-
440- private boolean _isScriptOrExtensionPresent (String value ) {
441- return value .contains ("_#" );
442- }
443447 }
444448
445449 // @since 2.12 to simplify logic a bit: should not use coercions when reading
0 commit comments