Fixed threading issues with MathException and MathRuntimeException

Jira: MATH-253

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@762107 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-04-05 15:33:06 +00:00
parent 48fcbcf982
commit 7822849ae5
3 changed files with 11 additions and 22 deletions

View File

@ -36,11 +36,8 @@ import java.util.ResourceBundle;
public class MathException extends Exception {
/** Serializable version identifier. */
private static final long serialVersionUID = -2803873247432645339L;
private static final long serialVersionUID = -9004610152740737812L;
/** Cache for resources bundle. */
private static ResourceBundle cachedResources = null;
/**
* Pattern used to build the message.
*/
@ -60,15 +57,11 @@ public class MathException extends Exception {
*/
private static String translate(String s, Locale locale) {
try {
if ((cachedResources == null) || (! cachedResources.getLocale().equals(locale))) {
// caching the resource bundle
cachedResources =
ResourceBundle bundle =
ResourceBundle.getBundle("org.apache.commons.math.MessagesResources", locale);
}
if (cachedResources.getLocale().getLanguage().equals(locale.getLanguage())) {
if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
// the value of the resource is the translated string
return cachedResources.getString(s);
return bundle.getString(s);
}
} catch (MissingResourceException mre) {

View File

@ -37,11 +37,8 @@ import java.util.ResourceBundle;
public class MathRuntimeException extends RuntimeException {
/** Serializable version identifier. */
private static final long serialVersionUID = 4184290229453587356L;
private static final long serialVersionUID = -5128983364075381060L;
/** Cache for resources bundle. */
private static ResourceBundle cachedResources = null;
/**
* Pattern used to build the message.
*/
@ -61,15 +58,11 @@ public class MathRuntimeException extends RuntimeException {
*/
private static String translate(final String s, final Locale locale) {
try {
if ((cachedResources == null) || (! cachedResources.getLocale().equals(locale))) {
// caching the resource bundle
cachedResources =
ResourceBundle bundle =
ResourceBundle.getBundle("org.apache.commons.math.MessagesResources", locale);
}
if (cachedResources.getLocale().getLanguage().equals(locale.getLanguage())) {
if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
// the value of the resource is the translated string
return cachedResources.getString(s);
return bundle.getString(s);
}
} catch (MissingResourceException mre) {

View File

@ -39,6 +39,9 @@ The <action> type attribute can be add,update,fix,remove.
</properties>
<body>
<release version="2.0" date="TBD" description="TBD">
<action dev="luc" type="fix" issue="MATH-253" due-to="Sebb">
Fixed threading issues with MathException and MathRuntimeException
</action>
<action dev="luc" type="fix" issue="MATH-254" due-to="Sebb">
Fixed threading issues with UnivariateRealSolverUtils factory
</action>