mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-23 21:30:26 +00:00
8157102: Avoid exceptional control flow in Configuration.getText
Reviewed-by: jjg
This commit is contained in:
parent
149821a78e
commit
6cc9359822
@ -714,43 +714,43 @@ public abstract class Configuration {
|
||||
}
|
||||
|
||||
public String getText(String key) {
|
||||
try {
|
||||
//Check the doclet specific properties file.
|
||||
return getDocletSpecificMsg().getText(key);
|
||||
} catch (Exception e) {
|
||||
//Check the shared properties file.
|
||||
return message.getText(key);
|
||||
// Check the doclet specific properties file.
|
||||
MessageRetriever docletMessage = getDocletSpecificMsg();
|
||||
if (docletMessage.containsKey(key)) {
|
||||
return docletMessage.getText(key);
|
||||
}
|
||||
// Check the shared properties file.
|
||||
return message.getText(key);
|
||||
}
|
||||
|
||||
public String getText(String key, String a1) {
|
||||
try {
|
||||
//Check the doclet specific properties file.
|
||||
return getDocletSpecificMsg().getText(key, a1);
|
||||
} catch (Exception e) {
|
||||
//Check the shared properties file.
|
||||
return message.getText(key, a1);
|
||||
// Check the doclet specific properties file.
|
||||
MessageRetriever docletMessage = getDocletSpecificMsg();
|
||||
if (docletMessage.containsKey(key)) {
|
||||
return docletMessage.getText(key, a1);
|
||||
}
|
||||
// Check the shared properties file.
|
||||
return message.getText(key, a1);
|
||||
}
|
||||
|
||||
public String getText(String key, String a1, String a2) {
|
||||
try {
|
||||
//Check the doclet specific properties file.
|
||||
return getDocletSpecificMsg().getText(key, a1, a2);
|
||||
} catch (Exception e) {
|
||||
//Check the shared properties file.
|
||||
return message.getText(key, a1, a2);
|
||||
// Check the doclet specific properties file.
|
||||
MessageRetriever docletMessage = getDocletSpecificMsg();
|
||||
if (docletMessage.containsKey(key)) {
|
||||
return docletMessage.getText(key, a1, a2);
|
||||
}
|
||||
// Check the shared properties file.
|
||||
return message.getText(key, a1, a2);
|
||||
}
|
||||
|
||||
public String getText(String key, String a1, String a2, String a3) {
|
||||
try {
|
||||
//Check the doclet specific properties file.
|
||||
return getDocletSpecificMsg().getText(key, a1, a2, a3);
|
||||
} catch (Exception e) {
|
||||
//Check the shared properties file.
|
||||
return message.getText(key, a1, a2, a3);
|
||||
// Check the doclet specific properties file.
|
||||
MessageRetriever docletMessage = getDocletSpecificMsg();
|
||||
if (docletMessage.containsKey(key)) {
|
||||
return docletMessage.getText(key, a1, a2, a3);
|
||||
}
|
||||
// Check the shared properties file.
|
||||
return message.getText(key, a1, a2, a3);
|
||||
}
|
||||
|
||||
public abstract Content newContent();
|
||||
|
||||
@ -83,6 +83,34 @@ public class MessageRetriever {
|
||||
this.resourcelocation = resourcelocation;
|
||||
}
|
||||
|
||||
private ResourceBundle initRB() {
|
||||
ResourceBundle bundle = messageRB;
|
||||
if (bundle == null) {
|
||||
try {
|
||||
messageRB = bundle =
|
||||
ResourceBundle.getBundle(resourcelocation, configuration.getLocale());
|
||||
} catch (MissingResourceException e) {
|
||||
throw new Error("Fatal: Resource (" + resourcelocation
|
||||
+ ") for javadoc doclets is missing.");
|
||||
}
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the given <code>key</code> can be retrieved
|
||||
* from this <code>MessageRetriever</code>
|
||||
*
|
||||
* @param key
|
||||
* the resource <code>key</code>
|
||||
* @return <code>true</code> if the given <code>key</code> is
|
||||
* contained in the underlying <code>ResourceBundle</code>.
|
||||
*/
|
||||
public boolean containsKey(String key) {
|
||||
ResourceBundle bundle = initRB();
|
||||
return bundle.containsKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and format message string from resource
|
||||
*
|
||||
@ -92,15 +120,8 @@ public class MessageRetriever {
|
||||
* exist in the properties file.
|
||||
*/
|
||||
public String getText(String key, Object... args) throws MissingResourceException {
|
||||
if (messageRB == null) {
|
||||
try {
|
||||
messageRB = ResourceBundle.getBundle(resourcelocation);
|
||||
} catch (MissingResourceException e) {
|
||||
throw new Error("Fatal: Resource (" + resourcelocation +
|
||||
") for javadoc doclets is missing.");
|
||||
}
|
||||
}
|
||||
String message = messageRB.getString(key);
|
||||
ResourceBundle bundle = initRB();
|
||||
String message = bundle.getString(key);
|
||||
return MessageFormat.format(message, args);
|
||||
}
|
||||
|
||||
|
||||
@ -894,43 +894,43 @@ public abstract class Configuration {
|
||||
}
|
||||
|
||||
public String getText(String key) {
|
||||
try {
|
||||
//Check the doclet specific properties file.
|
||||
return getDocletSpecificMsg().getText(key);
|
||||
} catch (Exception e) {
|
||||
//Check the shared properties file.
|
||||
return message.getText(key);
|
||||
// Check the doclet specific properties file.
|
||||
MessageRetriever docletMessage = getDocletSpecificMsg();
|
||||
if (docletMessage.containsKey(key)) {
|
||||
return docletMessage.getText(key);
|
||||
}
|
||||
// Check the shared properties file.
|
||||
return message.getText(key);
|
||||
}
|
||||
|
||||
public String getText(String key, String a1) {
|
||||
try {
|
||||
//Check the doclet specific properties file.
|
||||
return getDocletSpecificMsg().getText(key, a1);
|
||||
} catch (MissingResourceException e) {
|
||||
//Check the shared properties file.
|
||||
return message.getText(key, a1);
|
||||
// Check the doclet specific properties file.
|
||||
MessageRetriever docletMessage = getDocletSpecificMsg();
|
||||
if (docletMessage.containsKey(key)) {
|
||||
return docletMessage.getText(key, a1);
|
||||
}
|
||||
// Check the shared properties file.
|
||||
return message.getText(key, a1);
|
||||
}
|
||||
|
||||
public String getText(String key, String a1, String a2) {
|
||||
try {
|
||||
//Check the doclet specific properties file.
|
||||
return getDocletSpecificMsg().getText(key, a1, a2);
|
||||
} catch (MissingResourceException e) {
|
||||
//Check the shared properties file.
|
||||
return message.getText(key, a1, a2);
|
||||
// Check the doclet specific properties file.
|
||||
MessageRetriever docletMessage = getDocletSpecificMsg();
|
||||
if (docletMessage.containsKey(key)) {
|
||||
return docletMessage.getText(key, a1, a2);
|
||||
}
|
||||
// Check the shared properties file.
|
||||
return message.getText(key, a1, a2);
|
||||
}
|
||||
|
||||
public String getText(String key, String a1, String a2, String a3) {
|
||||
try {
|
||||
//Check the doclet specific properties file.
|
||||
return getDocletSpecificMsg().getText(key, a1, a2, a3);
|
||||
} catch (MissingResourceException e) {
|
||||
//Check the shared properties file.
|
||||
return message.getText(key, a1, a2, a3);
|
||||
// Check the doclet specific properties file.
|
||||
MessageRetriever docletMessage = getDocletSpecificMsg();
|
||||
if (docletMessage.containsKey(key)) {
|
||||
return docletMessage.getText(key, a1, a2, a3);
|
||||
}
|
||||
// Check the shared properties file.
|
||||
return message.getText(key, a1, a2, a3);
|
||||
}
|
||||
|
||||
public abstract Content newContent();
|
||||
|
||||
@ -86,15 +86,32 @@ public class MessageRetriever {
|
||||
this.resourcelocation = resourcelocation;
|
||||
}
|
||||
|
||||
private void initRB() {
|
||||
if (messageRB == null) {
|
||||
private ResourceBundle initRB() {
|
||||
ResourceBundle bundle = messageRB;
|
||||
if (bundle == null) {
|
||||
try {
|
||||
messageRB = ResourceBundle.getBundle(resourcelocation, configuration.getLocale());
|
||||
messageRB = bundle =
|
||||
ResourceBundle.getBundle(resourcelocation, configuration.getLocale());
|
||||
} catch (MissingResourceException e) {
|
||||
throw new Error("Fatal: Resource (" + resourcelocation
|
||||
+ ") for javadoc doclets is missing.");
|
||||
}
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the given <code>key</code> can be retrieved
|
||||
* from this <code>MessageRetriever</code>
|
||||
*
|
||||
* @param key
|
||||
* the resource <code>key</code>
|
||||
* @return <code>true</code> if the given <code>key</code> is
|
||||
* contained in the underlying <code>ResourceBundle</code>.
|
||||
*/
|
||||
public boolean containsKey(String key) {
|
||||
ResourceBundle bundle = initRB();
|
||||
return bundle.containsKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,8 +124,8 @@ public class MessageRetriever {
|
||||
* exist in the properties file.
|
||||
*/
|
||||
public String getText(String key, Object... args) throws MissingResourceException {
|
||||
initRB();
|
||||
String message = messageRB.getString(key);
|
||||
ResourceBundle bundle = initRB();
|
||||
String message = bundle.getString(key);
|
||||
return MessageFormat.format(message, args);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user