From 7822849ae5d6f780483b1987220eb96a4e3f852a Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Sun, 5 Apr 2009 15:33:06 +0000 Subject: [PATCH] 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 --- .../org/apache/commons/math/MathException.java | 15 ++++----------- .../apache/commons/math/MathRuntimeException.java | 15 ++++----------- src/site/xdoc/changes.xml | 3 +++ 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/java/org/apache/commons/math/MathException.java b/src/java/org/apache/commons/math/MathException.java index a4b5ce80a..3016a4867 100644 --- a/src/java/org/apache/commons/math/MathException.java +++ b/src/java/org/apache/commons/math/MathException.java @@ -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) { diff --git a/src/java/org/apache/commons/math/MathRuntimeException.java b/src/java/org/apache/commons/math/MathRuntimeException.java index 6925e6d1a..58877eac8 100644 --- a/src/java/org/apache/commons/math/MathRuntimeException.java +++ b/src/java/org/apache/commons/math/MathRuntimeException.java @@ -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) { diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index d49237b83..d6413e8c0 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -39,6 +39,9 @@ The type attribute can be add,update,fix,remove. + + Fixed threading issues with MathException and MathRuntimeException + Fixed threading issues with UnivariateRealSolverUtils factory