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

View File

@ -37,10 +37,7 @@ import java.util.ResourceBundle;
public class MathRuntimeException extends RuntimeException { public class MathRuntimeException extends RuntimeException {
/** Serializable version identifier. */ /** 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. * 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) { private static String translate(final String s, final Locale locale) {
try { try {
if ((cachedResources == null) || (! cachedResources.getLocale().equals(locale))) { ResourceBundle bundle =
// caching the resource bundle
cachedResources =
ResourceBundle.getBundle("org.apache.commons.math.MessagesResources", locale); ResourceBundle.getBundle("org.apache.commons.math.MessagesResources", locale);
} if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
if (cachedResources.getLocale().getLanguage().equals(locale.getLanguage())) {
// the value of the resource is the translated string // the value of the resource is the translated string
return cachedResources.getString(s); return bundle.getString(s);
} }
} catch (MissingResourceException mre) { } catch (MissingResourceException mre) {

View File

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