MCPcopy Create free account
hub / github.com/apache/tomcat / getString

Method getString

java/org/apache/naming/StringManager.java:91–118  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 5

testSecretMethod · 0.95
doTestPostMethod · 0.95

Calls 4

getStringMethod · 0.65
setLocaleMethod · 0.65
toStringMethod · 0.65
formatMethod · 0.65

Tested by 5

testSecretMethod · 0.76
doTestPostMethod · 0.76