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)
| 108 | * @throws IllegalArgumentException if <i>key</i> is null |
| 109 | */ |
| 110 | public String getString(String key) { |
| 111 | if (key == null) { |
| 112 | throw new IllegalArgumentException("key may not have a null value"); |
| 113 | } |
| 114 | |
| 115 | String str = null; |
| 116 | |
| 117 | try { |
| 118 | // Avoid NPE if bundle is null and treat it like an MRE |
| 119 | if (bundle != null) { |
| 120 | str = bundle.getString(key); |
| 121 | } |
| 122 | } catch (MissingResourceException ignore) { |
| 123 | // bad: shouldn't mask an exception the following way: |
| 124 | // str = "[cannot find message associated with key '" + key + |
| 125 | // "' due to " + mre + "]"; |
| 126 | // because it hides the fact that the String was missing |
| 127 | // from the calling code. |
| 128 | // good: could just throw the exception (or wrap it in another) |
| 129 | // but that would probably cause much havoc on existing |
| 130 | // code. |
| 131 | // better: consistent with container pattern to |
| 132 | // simply return null. Calling code can then do |
| 133 | // a null check. |
| 134 | } |
| 135 | |
| 136 | return str; |
| 137 | } |
| 138 | |
| 139 | |
| 140 | /** |