Get a string from the underlying resource bundle or return null if the String is not found. @param key to desired resource String @return resource String matching key from underlying bundle or null if not found. @throws IllegalArgumentException if key is null.
(String key)
| 89 | * @throws IllegalArgumentException if <i>key</i> is null. |
| 90 | */ |
| 91 | public String getString(String key) { |
| 92 | if (key == null) { |
| 93 | throw new IllegalArgumentException("key may not have a null value"); |
| 94 | } |
| 95 | |
| 96 | String str = null; |
| 97 | |
| 98 | try { |
| 99 | // Avoid NPE if bundle is null and treat it like an MRE |
| 100 | if (bundle != null) { |
| 101 | str = bundle.getString(key); |
| 102 | } |
| 103 | } catch (MissingResourceException ignore) { |
| 104 | // bad: shouldn't mask an exception the following way: |
| 105 | // str = "[cannot find message associated with key '" + key + "' due to " + mre + "]"; |
| 106 | // because it hides the fact that the String was missing |
| 107 | // from the calling code. |
| 108 | // good: could just throw the exception (or wrap it in another) |
| 109 | // but that would probably cause much havoc on existing |
| 110 | // code. |
| 111 | // better: consistent with container pattern to |
| 112 | // simply return null. Calling code can then do |
| 113 | // a null check. |
| 114 | // str is already set to null |
| 115 | } |
| 116 | |
| 117 | return str; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Get a string from the underlying resource bundle and format it with the given set of arguments. |