@@ -372,15 +372,31 @@ protected MessageFormat getMessageFormat(ResourceBundle bundle, String code, Loc
372
372
}
373
373
}
374
374
375
- private String getStringOrNull (ResourceBundle bundle , String key ) {
376
- try {
377
- return bundle .getString (key );
378
- }
379
- catch (MissingResourceException ex ) {
380
- // Assume key not found
381
- // -> do NOT throw the exception to allow for checking parent message source.
382
- return null ;
375
+ /**
376
+ * Efficiently retrieve the String value for the specified key,
377
+ * or return {@code null} if not found.
378
+ * <p>As of 4.2, the default implementation checks {@code containsKey}
379
+ * before it attempts to call {@code getString} (which would require
380
+ * catching {@code MissingResourceException} for key not found).
381
+ * <p>Can be overridden in subclasses.
382
+ * @param bundle the ResourceBundle to perform the lookup in
383
+ * @param key the key to look up
384
+ * @return the associated value, or {@code null} if none
385
+ * @since 4.2
386
+ * @see ResourceBundle#getString(String)
387
+ * @see ResourceBundle#containsKey(String)
388
+ */
389
+ protected String getStringOrNull (ResourceBundle bundle , String key ) {
390
+ if (bundle .containsKey (key )) {
391
+ try {
392
+ return bundle .getString (key );
393
+ }
394
+ catch (MissingResourceException ex ){
395
+ // Assume key not found for some other reason
396
+ // -> do NOT throw the exception to allow for checking parent message source.
397
+ }
383
398
}
399
+ return null ;
384
400
}
385
401
386
402
/**
0 commit comments