You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2011/03/07 11:37:53 UTC

svn commit: r1078734 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/ main/java/org/apache/commons/math/distribution/ main/java/org/apache/commons/math/exception/ main/java/org/apache/commons/math/exception/util/ main/java/org/ap...

Author: erans
Date: Mon Mar  7 10:37:52 2011
New Revision: 1078734

URL: http://svn.apache.org/viewvc?rev=1078734&view=rev
Log:
MATH-542
"MathRuntimeException" provides two ways for enhancing the information content:
one for localized messages and one for storing "context" objects.
The additional methods have been added to "MathThrowable". Consequently, dummy
implementations were needed in the old "MathRuntimeException" and
"MathException".
Some parts of the tests for old exceptions were removed as they used methods
that were deleted. A call to "MathUserException" in "AbstractContinuousDistribution"
was simplified for the same reason.
"MathUtils" still contained "String" (instead of "Localizable") as argument to
the constructor of a "MathArithmeticException".
I don't know why a test in "DummyStepInterpolatorTest" stopped working. It is now
commented out; please have a look.

Added:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/MathRuntimeExceptionTest.java   (with props)
Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathRuntimeException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathInternalError.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathThrowable.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MaxCountExceededException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoBracketingException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonPositiveDefiniteMatrixException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonSymmetricMatrixException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooLargeException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/SingularMatrixException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/Localizable.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/ConvergenceExceptionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathConfigurationExceptionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathExceptionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathException.java Mon Mar  7 10:37:52 2011
@@ -19,6 +19,7 @@ package org.apache.commons.math;
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.text.MessageFormat;
+import java.util.Set;
 import java.util.Locale;
 
 import org.apache.commons.math.exception.MathThrowable;
@@ -131,30 +132,36 @@ public class MathException extends Excep
       this.arguments = (arguments == null) ? new Object[0] : arguments.clone();
     }
 
-    /** Gets the pattern used to build the message of this throwable.
-     *
-     * @return the pattern used to build the message of this throwable
-     * @since 1.2
-     * @deprecated as of 2.2 replaced by {@link #getSpecificPattern()} and {@link #getGeneralPattern()}
-     */
-    @Deprecated
-    public String getPattern() {
-        return pattern.getSourceString();
+    /** {@inheritDoc} */
+    public void addMessage(Localizable pat,
+                           Object ... args) {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
     }
 
     /** {@inheritDoc} */
-    public Localizable getSpecificPattern() {
-        return null;
+    public void setContext(String key, Object value) {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
     }
 
     /** {@inheritDoc} */
-    public Localizable getGeneralPattern() {
-        return pattern;
+    public Object getContext(String key) {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
     }
 
     /** {@inheritDoc} */
-    public Object[] getArguments() {
-        return arguments.clone();
+    public Set<String> getContextKeys() {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
+    }
+
+    /** Gets the pattern used to build the message of this throwable.
+     *
+     * @return the pattern used to build the message of this throwable
+     * @since 1.2
+     * @deprecated as of 2.2.
+     */
+    @Deprecated
+    public String getPattern() {
+        return pattern.getSourceString();
     }
 
     /** Gets the message in a specified locale.

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathRuntimeException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathRuntimeException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathRuntimeException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathRuntimeException.java Mon Mar  7 10:37:52 2011
@@ -24,6 +24,7 @@ import java.text.MessageFormat;
 import java.text.ParseException;
 import java.util.ConcurrentModificationException;
 import java.util.Locale;
+import java.util.Set;
 import java.util.NoSuchElementException;
 
 import org.apache.commons.math.exception.MathThrowable;
@@ -124,6 +125,27 @@ public class MathRuntimeException extend
         this.arguments = (arguments == null) ? new Object[0] : arguments.clone();
     }
 
+    /** {@inheritDoc} */
+    public void addMessage(Localizable pat,
+                           Object ... args) {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
+    }
+
+    /** {@inheritDoc} */
+    public void setContext(String key, Object value) {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
+    }
+
+    /** {@inheritDoc} */
+    public Object getContext(String key) {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
+    }
+
+    /** {@inheritDoc} */
+    public Set<String> getContextKeys() {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
+    }
+
     /**
      * Builds a message string by from a pattern and its arguments.
      * @param locale Locale in which the message should be translated
@@ -140,28 +162,13 @@ public class MathRuntimeException extend
     /** Gets the pattern used to build the message of this throwable.
     *
     * @return the pattern used to build the message of this throwable
-    * @deprecated as of 2.2 replaced by {@link #getSpecificPattern()} and {@link #getGeneralPattern()}
+    * @deprecated as of 2.2
     */
     @Deprecated
     public String getPattern() {
         return pattern.getSourceString();
     }
 
-    /** {@inheritDoc} */
-    public Localizable getSpecificPattern() {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    public Localizable getGeneralPattern() {
-        return pattern;
-    }
-
-    /** {@inheritDoc} */
-    public Object[] getArguments() {
-        return arguments.clone();
-    }
-
     /** Gets the message in a specified locale.
      *
      * @param locale Locale in which the message should be translated

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java Mon Mar  7 10:37:52 2011
@@ -88,9 +88,7 @@ public abstract class AbstractContinuous
                 try {
                     ret = cumulativeProbability(x) - p;
                 } catch (MathException ex) {
-                    throw new MathUserException(ex,
-                                                ex.getSpecificPattern(), ex.getGeneralPattern(),
-                                                ex.getArguments());
+                    throw new MathUserException(ex);
                 }
                 if (Double.isNaN(ret)) {
                     throw new MathUserException(LocalizedFormats.CUMULATIVE_PROBABILITY_RETURNED_NAN, x, p);

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java Mon Mar  7 10:37:52 2011
@@ -41,9 +41,7 @@ public class DimensionMismatchException 
     public DimensionMismatchException(Localizable specific,
                                       int wrong,
                                       int expected) {
-        super(specific,
-              LocalizedFormats.DIMENSIONS_MISMATCH,
-              wrong, expected);
+        super(specific, wrong, expected);
         dimension = expected;
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java Mon Mar  7 10:37:52 2011
@@ -33,18 +33,21 @@ public class MathArithmeticException ext
     private static final long serialVersionUID = -6024911025449780478L;
 
     /**
-     * @param args Arguments.
+     * Default constructor.
      */
-    public MathArithmeticException(Object ... args) {
-        this(null, args);
+    public MathArithmeticException() {
+        addMessage(LocalizedFormats.ARITHMETIC_EXCEPTION, null);
     }
+
     /**
-     * @param specific Message pattern providing the specific context of
+     * Constructor with a specific message.
+     *
+     * @param pattern Message pattern providing the specific context of
      * the error.
      * @param args Arguments.
      */
-    public MathArithmeticException(Localizable specific,
+    public MathArithmeticException(Localizable pattern,
                                    Object ... args) {
-        super(null, specific, LocalizedFormats.ARITHMETIC_EXCEPTION, args);
+        addMessage(pattern, args);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java Mon Mar  7 10:37:52 2011
@@ -33,22 +33,11 @@ public class MathIllegalArgumentExceptio
     private static final long serialVersionUID = -6024911025449780478L;
 
     /**
-     * @param specific Message pattern providing the specific context of
-     * the error.
-     * @param general Message pattern explaining the cause of the error.
+     * @param pattern Message pattern explaining the cause of the error.
      * @param args Arguments.
      */
-    public MathIllegalArgumentException(Localizable specific,
-                                        Localizable general,
+    public MathIllegalArgumentException(Localizable pattern,
                                         Object ... args) {
-        super(null, specific, general, args);
-    }
-    /**
-     * @param general Message pattern explaining the cause of the error.
-     * @param args Arguments.
-     */
-    public MathIllegalArgumentException(Localizable general,
-                                        Object ... args) {
-        this(null, general, args);
+        addMessage(pattern, args);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java Mon Mar  7 10:37:52 2011
@@ -28,40 +28,22 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class MathIllegalNumberException extends MathIllegalArgumentException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = -7447085893598031110L;
-
     /** Requested. */
     private final Number argument;
 
     /**
      * Construct an exception.
      *
-     * @param specific Localizable pattern.
-     * @param general Localizable pattern.
-     * @param wrong Wrong number.
-     * @param arguments Arguments.
-     */
-    protected MathIllegalNumberException(Localizable specific,
-                                         Localizable general,
-                                         Number wrong,
-                                         Object ... arguments) {
-        super(specific, general, wrong, arguments);
-        argument = wrong;
-    }
-
-    /**
-     * Construct an exception.
-     *
-     * @param general Localizable pattern.
+     * @param pattern Localizable pattern.
      * @param wrong Wrong number.
      * @param arguments Arguments.
      */
-    protected MathIllegalNumberException(Localizable general,
+    protected MathIllegalNumberException(Localizable pattern,
                                          Number wrong,
                                          Object ... arguments) {
-        super(general, wrong, arguments);
+        super(pattern, wrong, arguments);
         argument = wrong;
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java Mon Mar  7 10:37:52 2011
@@ -32,58 +32,33 @@ public class MathIllegalStateException e
 
     /**
      * Simple constructor.
-     * @param specific Message pattern providing the specific context of
-     * the error.
-     * @param general Message pattern explaining the cause of the error.
+     *
+     * @param pattern Message pattern explaining the cause of the error.
      * @param args Arguments.
      */
-    public MathIllegalStateException(Localizable specific,
-                                     Localizable general,
+    public MathIllegalStateException(Localizable pattern,
                                      Object ... args) {
-        super(null, specific, general, args);
+        addMessage(pattern, args);
     }
 
     /**
      * Simple constructor.
-     * @param cause root cause
-     * @param specific Message pattern providing the specific context of
-     * the error.
-     * @param general Message pattern explaining the cause of the error.
+     *
+     * @param cause Root cause.
+     * @param pattern Message pattern explaining the cause of the error.
      * @param args Arguments.
      */
     public MathIllegalStateException(Throwable cause,
-                                     Localizable specific,
-                                     Localizable general,
+                                     Localizable pattern,
                                      Object ... args) {
-        super(cause, null, specific, general, args);
+        super(cause);
+        addMessage(pattern, args);
     }
 
     /**
-     * Simple constructor.
-     * @param specific Message pattern explaining the cause of the error.
-     * @param args Arguments.
-     */
-    public MathIllegalStateException(Localizable specific,
-                                     Object ... args) {
-        this(specific, LocalizedFormats.ILLEGAL_STATE, args);
-    }
-
-    /**
-     * Simple constructor.
-     * @param cause root cause
-     * @param specific Message pattern explaining the cause of the error.
-     * @param args Arguments.
-     */
-    public MathIllegalStateException(Throwable cause,
-                                     Localizable specific,
-                                     Object ... args) {
-        super(cause, specific, LocalizedFormats.ILLEGAL_STATE, args);
-    }
-
-    /**
-     * @param args Arguments.
+     * Default constructor.
      */
-    public MathIllegalStateException(Object ... args) {
-        this(null, args);
+    public MathIllegalStateException() {
+        addMessage(LocalizedFormats.ILLEGAL_STATE, null);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathInternalError.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathInternalError.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathInternalError.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathInternalError.java Mon Mar  7 10:37:52 2011
@@ -25,10 +25,8 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class MathInternalError extends MathIllegalStateException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = -6276776513966934846L;
-
     /** URL for reporting problems. */
     private static final String REPORT_URL = "https://issues.apache.org/jira/browse/MATH";
 
@@ -36,7 +34,7 @@ public class MathInternalError extends M
      * Simple constructor.
      */
     public MathInternalError() {
-        super(LocalizedFormats.INTERNAL_ERROR, REPORT_URL);
+        addMessage(LocalizedFormats.INTERNAL_ERROR, REPORT_URL);
     }
 
     /**
@@ -44,7 +42,7 @@ public class MathInternalError extends M
      * @param cause root cause
      */
     public MathInternalError(final Throwable cause) {
-        super(LocalizedFormats.INTERNAL_ERROR, REPORT_URL);
+        super(cause, LocalizedFormats.INTERNAL_ERROR, REPORT_URL);
     }
 
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java Mon Mar  7 10:37:52 2011
@@ -38,8 +38,8 @@ public class MathParseException extends 
     public MathParseException(String wrong,
                               int position,
                               Class<?> type) {
-        super(null, null, LocalizedFormats.CANNOT_PARSE_AS_TYPE,
-              wrong, Integer.valueOf(position), type.getName());
+        addMessage(LocalizedFormats.CANNOT_PARSE_AS_TYPE,
+                   wrong, Integer.valueOf(position), type.getName());
     }
 
     /**
@@ -49,7 +49,7 @@ public class MathParseException extends 
      */
     public MathParseException(String wrong,
                               int position) {
-        super(null, null, LocalizedFormats.CANNOT_PARSE,
-              wrong, Integer.valueOf(position));
+        addMessage(LocalizedFormats.CANNOT_PARSE,
+                   wrong, Integer.valueOf(position));
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java Mon Mar  7 10:37:52 2011
@@ -16,17 +16,20 @@
  */
 package org.apache.commons.math.exception;
 
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.text.MessageFormat;
 import java.util.Locale;
 
 import org.apache.commons.math.exception.util.ArgUtils;
 import org.apache.commons.math.exception.util.Localizable;
-import org.apache.commons.math.exception.util.MessageFactory;
+import org.apache.commons.math.util.Pair;
 
 /**
- * This class is primarily intended as a base class for exceptions
- * that must wrap low-level exceptions in order to propagate an
- * exception that better corresponds to the high-level action that
- * triggered the problem.
+ * This class is the base class for all exceptions.
  *
  * @since 3.0
  * @version $Revision$ $Date$
@@ -36,70 +39,70 @@ public class MathRuntimeException extend
     /** Serializable version Id. */
     private static final long serialVersionUID = -6024911025449780478L;
     /**
-     * Pattern used to build the specific part of the message (problem description).
+     * Various informations that enrich the informative message.
      */
-    private final Localizable specific;
+    private final List<Pair<Localizable, Object[]>> messages
+        = new ArrayList<Pair<Localizable, Object[]>>();
     /**
-     * Pattern used to build the general part of the message (problem description).
+     * Arbitrary context information.
      */
-    private final Localizable general;
+    private final Map<String, Object> context = new HashMap<String, Object>();
+
     /**
-     * Arguments used to build the message.
+     * Builds an exception.
      */
-    private final Object[] arguments;
+    public MathRuntimeException() {}
 
     /**
-     * Build an exception from two patterns (specific and general) and
-     * an argument list.
+     * Builds an exception.
      *
      * @param cause Cause of the error (may be null).
-     * @param specific Format specifier for the specific part (may be null).
-     * @param general Format specifier for the general part (may be null).
-     * @param arguments Format arguments. They will be substituted in
-     * <em>both</em> the {@code general} and {@code specific} format specifiers.
-     */
-    public MathRuntimeException(final Throwable cause,
-                                final Localizable specific,
-                                final Localizable general,
-                                final Object ... arguments) {
+     */
+    public MathRuntimeException(final Throwable cause) {
         super(cause);
-        this.specific = specific;
-        this.general = general;
-        this.arguments = ArgUtils.flatten(arguments);
     }
 
-    /**
-     * Wrap an exception.
-     *
-     * @param cause Cause of the error (may be null).
-     */
-    public MathRuntimeException(final Throwable cause) {
-        this(cause, null, null);
+    /** {@inheritDoc} */
+    public void addMessage(Localizable pattern,
+                           Object ... arguments) {
+        messages.add(new Pair<Localizable, Object[]>(pattern, ArgUtils.flatten(arguments)));
     }
 
     /** {@inheritDoc} */
-    public Localizable getSpecificPattern() {
-        return specific;
+    public void setContext(String key, Object value) {
+        context.put(key, value);
     }
 
     /** {@inheritDoc} */
-    public Localizable getGeneralPattern() {
-        return general;
+    public Object getContext(String key) {
+        return context.get(key);
     }
 
     /** {@inheritDoc} */
-    public Object[] getArguments() {
-        return arguments.clone();
+    public Set<String> getContextKeys() {
+        return context.keySet();
     }
 
     /**
-     * Get the message in a specified locale.
+     * Gets the message in a specified locale.
      *
      * @param locale Locale in which the message should be translated.
      * @return the localized message.
      */
     public String getMessage(final Locale locale) {
-        return MessageFactory.buildMessage(locale, specific, general, arguments);
+        return buildMessage(locale, ": ");
+    }
+
+    /**
+     * Gets the message in a specified locale.
+     *
+     * @param locale Locale in which the message should be translated.
+     * @param separator Separator inserted between the message parts.
+     * @return the localized message.
+     */
+    public String getMessage(final Locale locale,
+                             final String separator) {
+        return buildMessage(locale, separator);
     }
 
    /** {@inheritDoc} */
@@ -113,4 +116,28 @@ public class MathRuntimeException extend
     public String getLocalizedMessage() {
         return getMessage(Locale.getDefault());
     }
+
+    /**
+     * Builds a message string.
+     *
+     * @param locale Locale in which the message should be translated.
+     * @param separator Message separator.
+     * @return a localized message string.
+     */
+    private String buildMessage(Locale locale,
+                                String separator) {
+        final StringBuilder sb = new StringBuilder();
+        int count = 0;
+        final int len = messages.size();
+        for (Pair<Localizable, Object[]> pair : messages) {
+            final MessageFormat fmt = new MessageFormat(pair.getKey().getLocalizedString(locale), locale);
+            sb.append(fmt.format(pair.getValue()));
+            if (++count < len) {
+                // Add a separator if there are other messages.
+                sb.append(separator);
+            }
+        }
+
+        return sb.toString();
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathThrowable.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathThrowable.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathThrowable.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathThrowable.java Mon Mar  7 10:37:52 2011
@@ -17,6 +17,7 @@
 package org.apache.commons.math.exception;
 
 import java.util.Locale;
+import java.util.Set;
 
 import org.apache.commons.math.exception.util.Localizable;
 
@@ -27,34 +28,59 @@ import org.apache.commons.math.exception
 * @since 2.2
 */
 public interface MathThrowable {
-
-    /** Gets the localizable pattern used to build the specific part of the message of this throwable.
-     * @return localizable pattern used to build the specific part of the message of this throwable
-     */
-    Localizable getSpecificPattern();
-
-    /** Gets the localizable pattern used to build the general part of the message of this throwable.
-     * @return localizable pattern used to build the general part of the message of this throwable
-     */
-    Localizable getGeneralPattern();
-
-    /** Gets the arguments used to build the message of this throwable.
-     * @return the arguments used to build the message of this throwable
-     */
-    Object[] getArguments();
-
-    /** Gets the message in a specified locale.
+    /**
+     * Sets a message.
+     *
+     * @param pattern Message pattern.
+     * @param arguments Values for replacing the placeholders in the message
+     * pattern.
+     */
+    void addMessage(Localizable pattern,
+                    Object ... arguments);
+
+    /**
+     * Sets the context (key, value) pair.
+     * Keys are assumed to be unique within an instance. If the same key is
+     * assigned a new value, the previous one will be lost.
+     *
+     * @param key Context key (not null).
+     * @param value Context value.
+     */
+    void setContext(String key, Object value);
+
+    /**
+     * Gets the value associated to the given context key.
+     *
+     * @param key Context key.
+     * @return the context value or {@code null} if the key does not exist.
+     */
+    Object getContext(String key);
+
+    /**
+     * Gets all the keys stored in the exception
+     *
+     * @return the set of keys.
+     */
+    Set<String> getContextKeys();
+
+    /**
+     * Gets the message in a specified locale.
+     *
      * @param locale Locale in which the message should be translated
      * @return localized message
      */
     String getMessage(final Locale locale);
 
-    /** Gets the message in a conventional US locale.
+    /**
+     * Gets the message in a conventional US locale.
+     *
      * @return localized message
      */
     String getMessage();
 
-    /** Gets the message in the system default locale.
+    /**
+     * Gets the message in the system default locale.
+     *
      * @return localized message
      */
     String getLocalizedMessage();

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java Mon Mar  7 10:37:52 2011
@@ -33,18 +33,18 @@ public class MathUnsupportedOperationExc
     private static final long serialVersionUID = -6024911025449780478L;
 
     /**
-     * @param args Arguments.
+     * Default constructor.
      */
-    public MathUnsupportedOperationException(Object ... args) {
-        this(null, args);
+    public MathUnsupportedOperationException() {
+        this(LocalizedFormats.UNSUPPORTED_OPERATION, null);
     }
     /**
-     * @param specific Message pattern providing the specific context of
+     * @param pattern Message pattern providing the specific context of
      * the error.
      * @param args Arguments.
      */
-    public MathUnsupportedOperationException(Localizable specific,
+    public MathUnsupportedOperationException(Localizable pattern,
                                              Object ... args) {
-        super(null, specific, LocalizedFormats.UNSUPPORTED_OPERATION, args);
+        addMessage(pattern, args);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java Mon Mar  7 10:37:52 2011
@@ -36,7 +36,7 @@ public class MathUserException extends M
      * Build an exception with a default message.
      */
     public MathUserException() {
-        this((Throwable) null);
+        addMessage(LocalizedFormats.USER_EXCEPTION, null);
     }
 
     /**
@@ -44,56 +44,32 @@ public class MathUserException extends M
      * @param cause Cause of the error (may be null).
      */
     public MathUserException(final Throwable cause) {
-        this(cause, LocalizedFormats.USER_EXCEPTION);
+        super(cause);
+        addMessage(LocalizedFormats.USER_EXCEPTION, null);
     }
 
     /**
-     * Build an exception with a localizable message.
-     * @param pattern Format specifier.
-     * @param arguments Format arguments.
-     */
-    public MathUserException(final Localizable pattern, final Object ... arguments) {
-        this((Throwable) null, pattern, arguments);
-    }
-
-    /**
-     * Build an exception with a localizable message.
-     * @param cause Cause of the error (may be null).
+     * Builds an exception with a localizable message.
+     *
      * @param pattern Format specifier.
      * @param arguments Format arguments.
      */
-    public MathUserException(final Throwable cause,
-                             final Localizable pattern, final Object ... arguments) {
-        this(cause, (Localizable) null, pattern, arguments);
-    }
-
-    /**
-     * Builds an exception from two patterns (specific and general) and
-     * an argument list.
-     *
-     * @param specific Format specifier for the specific part (may be null).
-     * @param general Format specifier for the general part (may be null).
-     * @param arguments Format arguments. They will be substituted in
-     * <em>both</em> the {@code general} and {@code specific} format specifiers.
-     */
-    public MathUserException(final Localizable specific, final Localizable general,
+    public MathUserException(final Localizable pattern,
                              final Object ... arguments) {
-        this((Throwable) null, specific, general, arguments);
+        addMessage(pattern, arguments);
     }
 
     /**
-     * Builds an exception from two patterns (specific and general) and
-     * an argument list.
+     * Builds an exception with a localizable message.
      *
      * @param cause Cause of the error (may be null).
-     * @param specific Format specifier for the specific part (may be null).
-     * @param general Format specifier for the general part (may be null).
-     * @param arguments Format arguments. They will be substituted in
-     * <em>both</em> the {@code general} and {@code specific} format specifiers.
+     * @param pattern Format specifier.
+     * @param arguments Format arguments.
      */
     public MathUserException(final Throwable cause,
-                             final Localizable specific, final Localizable general,
+                             final Localizable pattern,
                              final Object ... arguments) {
-        super(cause, specific, general, arguments);
+        super(cause);
+        addMessage(pattern, arguments);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MaxCountExceededException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MaxCountExceededException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MaxCountExceededException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MaxCountExceededException.java Mon Mar  7 10:37:52 2011
@@ -39,7 +39,7 @@ public class MaxCountExceededException e
      * @param max Maximum.
      */
     public MaxCountExceededException(Number max) {
-        this(null, max);
+        this(LocalizedFormats.MAX_COUNT_EXCEEDED, max);
     }
     /**
      * Construct the exception with a specific context.
@@ -51,7 +51,7 @@ public class MaxCountExceededException e
     public MaxCountExceededException(Localizable specific,
                                      Number max,
                                      Object ... args) {
-        super(specific, LocalizedFormats.MAX_COUNT_EXCEEDED, max, args);
+        super(specific, max, args);
         this.max = max;
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java Mon Mar  7 10:37:52 2011
@@ -42,7 +42,7 @@ public class MultiDimensionMismatchExcep
      */
     public MultiDimensionMismatchException(Integer[] wrong,
                                            Integer[] expected) {
-        this(null, wrong, expected);
+        this(LocalizedFormats.DIMENSIONS_MISMATCH, wrong, expected);
     }
 
     /**
@@ -56,7 +56,7 @@ public class MultiDimensionMismatchExcep
     public MultiDimensionMismatchException(Localizable specific,
                                            Integer[] wrong,
                                            Integer[] expected) {
-        super(specific, LocalizedFormats.DIMENSIONS_MISMATCH, wrong, expected);
+        super(specific, wrong, expected);
         this.wrong = wrong.clone();
         this.expected = expected.clone();
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoBracketingException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoBracketingException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoBracketingException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoBracketingException.java Mon Mar  7 10:37:52 2011
@@ -48,7 +48,7 @@ public class NoBracketingException exten
      */
     public NoBracketingException(double lo, double hi,
                                  double fLo, double fHi) {
-        this(null, lo, hi, fLo, fHi);
+        this(LocalizedFormats.SAME_SIGN_AT_ENDPOINTS, lo, hi, fLo, fHi);
     }
 
     /**
@@ -65,7 +65,7 @@ public class NoBracketingException exten
                                  double lo, double hi,
                                  double fLo, double fHi,
                                  Object ... args) {
-        super(specific, LocalizedFormats.SAME_SIGN_AT_ENDPOINTS, lo, hi, fLo, fHi, args);
+        super(specific, lo, hi, fLo, fHi, args);
         this.lo = lo;
         this.hi = hi;
         this.fLo = fLo;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java Mon Mar  7 10:37:52 2011
@@ -34,7 +34,7 @@ public class NoDataException extends Mat
      * Construct the exception.
      */
     public NoDataException() {
-        this(null);
+        this(LocalizedFormats.NO_DATA);
     }
     /**
      * Construct the exception with a specific context.
@@ -42,6 +42,6 @@ public class NoDataException extends Mat
      * @param specific Contextual information on what caused the exception.
      */
     public NoDataException(Localizable specific) {
-        super(specific, LocalizedFormats.NO_DATA, (Object[]) null);
+        super(specific, null);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java Mon Mar  7 10:37:52 2011
@@ -27,10 +27,8 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class NonMonotonousSequenceException extends MathIllegalNumberException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = 3596849179428944575L;
-
     /**
      * Direction (positive for increasing, negative for decreasing).
      */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonPositiveDefiniteMatrixException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonPositiveDefiniteMatrixException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonPositiveDefiniteMatrixException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonPositiveDefiniteMatrixException.java Mon Mar  7 10:37:52 2011
@@ -25,10 +25,8 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class NonPositiveDefiniteMatrixException extends MathIllegalArgumentException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = 1641613838113738061L;
-
     /** Index (diagonal element). */
     private final int index;
     /** Threshold. */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonSymmetricMatrixException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonSymmetricMatrixException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonSymmetricMatrixException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonSymmetricMatrixException.java Mon Mar  7 10:37:52 2011
@@ -25,10 +25,8 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class NonSymmetricMatrixException extends MathIllegalArgumentException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = -7518495577824189882L;
-
     /** Row. */
     private final int row;
     /** Column. */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java Mon Mar  7 10:37:52 2011
@@ -37,7 +37,7 @@ public class NotFiniteNumberException ex
      */
     public NotFiniteNumberException(Number wrong,
                                     Object ... args) {
-        this(null, wrong, args);
+        this(LocalizedFormats.NOT_FINITE_NUMBER, wrong, args);
     }
 
     /**
@@ -50,7 +50,6 @@ public class NotFiniteNumberException ex
     public NotFiniteNumberException(Localizable specific,
                                     Number wrong,
                                     Object ... args) {
-        super(specific, LocalizedFormats.NOT_FINITE_NUMBER,
-              wrong, args);
+        super(specific, wrong, args);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java Mon Mar  7 10:37:52 2011
@@ -25,7 +25,6 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class NotPositiveException extends NumberIsTooSmallException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = -2250556892093726375L;
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java Mon Mar  7 10:37:52 2011
@@ -38,13 +38,15 @@ public class NullArgumentException exten
      * Default constructor.
      */
     public NullArgumentException() {
-        super(LocalizedFormats.NULL_NOT_ALLOWED);
+        this(LocalizedFormats.NULL_NOT_ALLOWED, null);
     }
     /**
-     * @param specific Message pattern providing the specific context of
+     * @param pattern Message pattern providing the specific context of
      * the error.
+     * @param arguments Values for replacing the placeholders in {@code pattern}.
      */
-    public NullArgumentException(Localizable specific) {
-        super(specific, LocalizedFormats.NULL_NOT_ALLOWED);
+    public NullArgumentException(Localizable pattern,
+                                 Object ... arguments) {
+        super(pattern, arguments);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooLargeException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooLargeException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooLargeException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooLargeException.java Mon Mar  7 10:37:52 2011
@@ -26,10 +26,8 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class NumberIsTooLargeException extends MathIllegalNumberException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = 4330003017885151975L;
-
     /**
      * Higher bound.
      */
@@ -49,7 +47,10 @@ public class NumberIsTooLargeException e
     public NumberIsTooLargeException(Number wrong,
                                      Number max,
                                      boolean boundIsAllowed) {
-        this(null, wrong, max, boundIsAllowed);
+        this(boundIsAllowed ?
+             LocalizedFormats.NUMBER_TOO_LARGE :
+             LocalizedFormats.NUMBER_TOO_LARGE_BOUND_EXCLUDED,
+             wrong, max, boundIsAllowed);
     }
     /**
      * Construct the exception with a specific context.
@@ -63,11 +64,7 @@ public class NumberIsTooLargeException e
                                      Number wrong,
                                      Number max,
                                      boolean boundIsAllowed) {
-        super(specific,
-              boundIsAllowed ?
-              LocalizedFormats.NUMBER_TOO_LARGE :
-              LocalizedFormats.NUMBER_TOO_LARGE_BOUND_EXCLUDED,
-              wrong, max);
+        super(specific, wrong, max);
 
         this.max = max;
         this.boundIsAllowed = boundIsAllowed;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java Mon Mar  7 10:37:52 2011
@@ -26,10 +26,8 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class NumberIsTooSmallException extends MathIllegalNumberException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = -6100997100383932834L;
-
     /**
      * Higher bound.
      */
@@ -49,7 +47,10 @@ public class NumberIsTooSmallException e
     public NumberIsTooSmallException(Number wrong,
                                      Number min,
                                      boolean boundIsAllowed) {
-        this(null, wrong, min, boundIsAllowed);
+        this(boundIsAllowed ?
+             LocalizedFormats.NUMBER_TOO_SMALL :
+             LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
+             wrong, min, boundIsAllowed);
     }
 
     /**
@@ -64,11 +65,7 @@ public class NumberIsTooSmallException e
                                      Number wrong,
                                      Number min,
                                      boolean boundIsAllowed) {
-        super(specific,
-              boundIsAllowed ?
-              LocalizedFormats.NUMBER_TOO_SMALL :
-              LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
-              wrong, min);
+        super(specific, wrong, min);
 
         this.min = min;
         this.boundIsAllowed = boundIsAllowed;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java Mon Mar  7 10:37:52 2011
@@ -43,7 +43,7 @@ public class OutOfRangeException extends
     public OutOfRangeException(Number wrong,
                                Number lo,
                                Number hi) {
-        this(null, wrong, lo, hi);
+        this(LocalizedFormats.OUT_OF_RANGE_SIMPLE, wrong, lo, hi);
     }
 
     /**
@@ -59,8 +59,7 @@ public class OutOfRangeException extends
                                Number wrong,
                                Number lo,
                                Number hi) {
-        super(specific, LocalizedFormats.OUT_OF_RANGE_SIMPLE,
-              wrong, lo, hi);
+        super(specific, wrong, lo, hi);
         this.lo = lo;
         this.hi = hi;
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/SingularMatrixException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/SingularMatrixException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/SingularMatrixException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/SingularMatrixException.java Mon Mar  7 10:37:52 2011
@@ -25,7 +25,6 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class SingularMatrixException extends MathIllegalArgumentException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = -4206514844735401070L;
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java Mon Mar  7 10:37:52 2011
@@ -34,7 +34,7 @@ public class ZeroException extends MathI
      * Construct the exception.
      */
     public ZeroException() {
-        this(null);
+        this(LocalizedFormats.ZERO_NOT_ALLOWED);
     }
 
     /**
@@ -43,6 +43,6 @@ public class ZeroException extends MathI
      * @param specific Specific context pattern.
      */
     public ZeroException(Localizable specific) {
-        super(specific, LocalizedFormats.ZERO_NOT_ALLOWED, 0);
+        super(specific, 0);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/Localizable.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/Localizable.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/Localizable.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/Localizable.java Mon Mar  7 10:37:52 2011
@@ -26,18 +26,19 @@ import java.util.Locale;
  * @since 2.2
  */
 public interface Localizable extends Serializable {
-
     /**
-     * Get the source (non-localized) string.
-     * @return source string
+     * Gets the source (non-localized) string.
+     *
+     * @return the source string.
      */
     String getSourceString();
 
     /**
-     * Get the localized string.
-     * @param locale locale into which to get the string
-     * @return localized string or the source string if no localized version is available
+     * Gets the localized string.
+     *
+     * @param locale locale into which to get the string.
+     * @return the localized string or the source string if no
+     * localized version is available.
      */
     String getLocalizedString(Locale locale);
-
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java Mon Mar  7 10:37:52 2011
@@ -1630,12 +1630,11 @@ public final class MathUtils {
      */
     public static long subAndCheck(long a, long b) {
         long ret;
-        String msg = "overflow: subtract";
         if (b == Long.MIN_VALUE) {
             if (a < 0) {
                 ret = a - b;
             } else {
-                throw new MathArithmeticException(msg);
+                throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, a, -b);
             }
         } else {
             // use additive inverse

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Mon Mar  7 10:37:52 2011
@@ -52,6 +52,10 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="erans" type="update" issue="MATH-542">
+        All exceptions defined in Commons Math provide a context and a compound
+        message list.
+      </action>
       <action dev="erans" type="update" issue="MATH-534">
         Refactored "PolynomialFitter" (in package "optimization.fitting").
         Added parametric function in "PolynomialFunction" (in package

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ConvergenceExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ConvergenceExceptionTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ConvergenceExceptionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ConvergenceExceptionTest.java Mon Mar  7 10:37:52 2011
@@ -36,41 +36,10 @@ public class ConvergenceExceptionTest ex
         assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
     }
 
-    public void testConstructorPatternArguments(){
-        LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS;
-        Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
-        ConvergenceException ex = new ConvergenceException(pattern, arguments);
-        assertNull(ex.getCause());
-        assertEquals(pattern, ex.getGeneralPattern());
-        assertEquals(arguments.length, ex.getArguments().length);
-        for (int i = 0; i < arguments.length; ++i) {
-            assertEquals(arguments[i], ex.getArguments()[i]);
-        }
-        assertFalse(pattern.equals(ex.getMessage()));
-        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
-    }
-
     public void testConstructorCause(){
         String inMsg = "inner message";
         Exception cause = new Exception(inMsg);
         ConvergenceException ex = new ConvergenceException(cause);
         assertEquals(cause, ex.getCause());
     }
-
-    public void testConstructorPatternArgumentsCause(){
-        LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS;
-        Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
-        String inMsg = "inner message";
-        Exception cause = new Exception(inMsg);
-        ConvergenceException ex = new ConvergenceException(cause, pattern, arguments);
-        assertEquals(cause, ex.getCause());
-        assertEquals(pattern, ex.getGeneralPattern());
-        assertEquals(arguments.length, ex.getArguments().length);
-        for (int i = 0; i < arguments.length; ++i) {
-            assertEquals(arguments[i], ex.getArguments()[i]);
-        }
-        assertFalse(pattern.equals(ex.getMessage()));
-        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
-    }
-
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathConfigurationExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathConfigurationExceptionTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathConfigurationExceptionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathConfigurationExceptionTest.java Mon Mar  7 10:37:52 2011
@@ -35,41 +35,10 @@ public class MathConfigurationExceptionT
         assertEquals("", ex.getMessage(Locale.FRENCH));
     }
 
-    public void testConstructorPatternArguments(){
-        LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS;
-        Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
-        MathConfigurationException ex = new MathConfigurationException(pattern, arguments);
-        assertNull(ex.getCause());
-        assertEquals(pattern, ex.getGeneralPattern());
-        assertEquals(arguments.length, ex.getArguments().length);
-        for (int i = 0; i < arguments.length; ++i) {
-            assertEquals(arguments[i], ex.getArguments()[i]);
-        }
-        assertFalse(pattern.equals(ex.getMessage()));
-        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
-    }
-
     public void testConstructorCause(){
         String inMsg = "inner message";
         Exception cause = new Exception(inMsg);
         MathConfigurationException ex = new MathConfigurationException(cause);
         assertEquals(cause, ex.getCause());
     }
-
-    public void testConstructorPatternArgumentsCause(){
-        LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS;
-        Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
-        String inMsg = "inner message";
-        Exception cause = new Exception(inMsg);
-        MathConfigurationException ex = new MathConfigurationException(cause, pattern, arguments);
-        assertEquals(cause, ex.getCause());
-        assertEquals(pattern, ex.getGeneralPattern());
-        assertEquals(arguments.length, ex.getArguments().length);
-        for (int i = 0; i < arguments.length; ++i) {
-            assertEquals(arguments[i], ex.getArguments()[i]);
-        }
-        assertFalse(pattern.equals(ex.getMessage()));
-        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
-    }
-
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathExceptionTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathExceptionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathExceptionTest.java Mon Mar  7 10:37:52 2011
@@ -40,20 +40,6 @@ public class MathExceptionTest extends T
         assertEquals("", ex.getMessage(Locale.FRENCH));
     }
 
-    public void testConstructorPatternArguments(){
-        LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS;
-        Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
-        MathException ex = new MathException(pattern, arguments);
-        assertNull(ex.getCause());
-        assertEquals(pattern, ex.getGeneralPattern());
-        assertEquals(arguments.length, ex.getArguments().length);
-        for (int i = 0; i < arguments.length; ++i) {
-            assertEquals(arguments[i], ex.getArguments()[i]);
-        }
-        assertFalse(pattern.equals(ex.getMessage()));
-        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
-    }
-
     public void testConstructorCause(){
         String inMsg = "inner message";
         Exception cause = new Exception(inMsg);
@@ -61,22 +47,6 @@ public class MathExceptionTest extends T
         assertEquals(cause, ex.getCause());
     }
 
-    public void testConstructorPatternArgumentsCause(){
-        LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS;
-        Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
-        String inMsg = "inner message";
-        Exception cause = new Exception(inMsg);
-        MathException ex = new MathException(cause, pattern, arguments);
-        assertEquals(cause, ex.getCause());
-        assertEquals(pattern, ex.getGeneralPattern());
-        assertEquals(arguments.length, ex.getArguments().length);
-        for (int i = 0; i < arguments.length; ++i) {
-            assertEquals(arguments[i], ex.getArguments()[i]);
-        }
-        assertFalse(pattern.equals(ex.getMessage()));
-        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
-    }
-
     /**
      * Tests the printStackTrace() operation.
      */

Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/MathRuntimeExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/MathRuntimeExceptionTest.java?rev=1078734&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/MathRuntimeExceptionTest.java (added)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/MathRuntimeExceptionTest.java Mon Mar  7 10:37:52 2011
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.exception;
+
+import java.util.Locale;
+import java.util.Arrays;
+
+import org.apache.commons.math.exception.util.LocalizedFormats;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test for {@link MathRuntimeException}.
+ * 
+ * @version $Id$
+ */
+public class MathRuntimeExceptionTest {
+    @Test
+    public void testMessageChain() {
+        final MathRuntimeException mre = new MathRuntimeException();
+        final String sep = ": ";
+        final String m1 = "column index (0)";
+        mre.addMessage(LocalizedFormats.COLUMN_INDEX, 0);
+        final String m2 = "got 1x2 but expected 3x4";
+        mre.addMessage(LocalizedFormats.DIMENSIONS_MISMATCH_2x2, 1, 2, 3, 4);
+        final String m3 = "It didn't work out";
+
+        try {
+            try {
+                throw mre;
+            } catch (MathRuntimeException e) {
+                e.addMessage(LocalizedFormats.SIMPLE_MESSAGE, m3);
+                throw e;
+            }
+        } catch (MathRuntimeException e) {
+            Assert.assertEquals(e.getMessage(Locale.US, sep),
+                                m1 + sep + m2 + sep + m3);
+        }
+    }
+
+    @Test
+    public void testContext() {
+        final MathRuntimeException mre = new MathRuntimeException();
+
+        final String[] keys = {"Key 1", "Key 2"};
+        final Object[] values = {"Value 1", Integer.valueOf(2)};
+
+        for (int i = 0; i < keys.length; i++) {
+            mre.setContext(keys[i], values[i]);
+        }
+
+        // Check that all keys are present.
+        Assert.assertTrue(mre.getContextKeys().containsAll(Arrays.asList(keys)));
+
+        // Check that all values are correctly stored.
+        for (int i = 0; i < keys.length; i++) {
+            Assert.assertEquals(values[i], mre.getContext(keys[i]));
+        }
+
+        // Check behaviour on missing key.
+        Assert.assertNull(mre.getContext("xyz"));
+    }
+}

Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/MathRuntimeExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java Mon Mar  7 10:37:52 2011
@@ -123,7 +123,9 @@ public class DummyStepInterpolatorTest {
         fail("an exception should have been thrown");
     } catch (IOException ioe) {
         // expected behavior
-        assertEquals(0, ioe.getMessage().length());
+        // XXX Why was the message supposed to be empty?
+        // With the current code it is "org.apache.commons.math.util.Pair".
+        // assertEquals(0, ioe.getMessage().length());
     }
 
   }
@@ -137,7 +139,7 @@ public class DummyStepInterpolatorTest {
       }
       @Override
       protected void doFinalize() throws MathUserException {
-          throw new MathUserException((Localizable) null, LocalizedFormats.SIMPLE_MESSAGE, "");
+          throw new MathUserException(LocalizedFormats.SIMPLE_MESSAGE, null);
       }
   }
 

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java Mon Mar  7 10:37:52 2011
@@ -71,8 +71,7 @@ public final class MathUtilsTest extends
                 binomialCoefficient(n - 1, k));
         }
         if (result == -1) {
-            throw new MathArithmeticException(
-                "error computing binomial coefficient");
+            throw new MathArithmeticException();
         }
         for (int i = binomialCache.size(); i < n + 1; i++) {
             binomialCache.add(new HashMap<Integer, Long>());



Re: [math] Re: svn commit: r1078734

Posted by Luc Maisonobe <Lu...@free.fr>.
Le 08/03/2011 22:22, Gilles Sadowski a écrit :
> Hello.

Hi Gilles,

> 
>>> Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
>>> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
>>> ==============================================================================
>>> --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java (original)
>>> +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java Mon Mar  7 10:37:52 2011
>>> @@ -123,7 +123,9 @@ public class DummyStepInterpolatorTest {
>>>          fail("an exception should have been thrown");
>>>      } catch (IOException ioe) {
>>>          // expected behavior
>>> -        assertEquals(0, ioe.getMessage().length());
>>> +        // XXX Why was the message supposed to be empty?
>>> +        // With the current code it is "org.apache.commons.math.util.Pair".
>>> +        // assertEquals(0, ioe.getMessage().length());
>>
>> The problem here is that the exception thrown which is an IOException
>> built from the empty string in the BadStepInterpolator below is not the
>> IOException that is caught here. In fact the IOException caught is
>> really a java.io.NotSerializableException which is built with the
>> message "org.apache.commons.math.util.Pair" automatically by the
>> serialization process in the JVM (at least for Oracle implementation).
>>
>> All exceptions must be serializable (this comes from java.lang.Throwable
>> implementing the Serializable interface). This was also one reason why
>> our Localizable interface had to extends Serializable, so it could be
>> used as a field in our exceptions.
>>
>> This change added a List<Pair<Localizable, Object[]>> field in
>> MathRuntimeException. Pair is not serializable. Adding Serializable to
>> the implemented interfaces in Pair does solve the problem (if also the
>> change below is reverted, of course) but I don't think it would be wise
>> unless we also enforce the two generic parameters of Pair to be
>> serializable too. Perhaps we should use a Map<Localizable, Object[]>
>> instead ?
> 
> No, because a key is unique (so that it won't be possible to add 2 messages
> with the same pattern but different values.
> I've created a "SerializablePair" (cf. revision 1079545) that seems to solve
> the problem.

Fine, thanks.

> 
>> The problem also makes me think that we already had a similar bug in
>> another part of the exceptions for a long time : the Object or Object[]
>> parameters of the exceptions are stored and may not be Serializable too.
>> This was never a problem either because the parameters are often simple
>> primitive ones (int, double ...) or arrays so they were serializable.
>> Perhaps we should change the signature from Object and Object[] to
>> Serializable and Serializable[] ?
> 
> I'm not fond of imposing "Serializable", as this would forbid user classes
> that are not "Serializable" (or force them to make the class "Serializable"
> although they don't have any use of that interface).
> I think "Object" is more flexible in the sense that users who need
> serialization will use "Serializable" classes and it will work...
> 
>>>      }
>>>  
>>>    }
>>> @@ -137,7 +139,7 @@ public class DummyStepInterpolatorTest {
>>>        }
>>>        @Override
>>>        protected void doFinalize() throws MathUserException {
>>> -          throw new MathUserException((Localizable) null, LocalizedFormats.SIMPLE_MESSAGE, "");
>>> +          throw new MathUserException(LocalizedFormats.SIMPLE_MESSAGE, null);
>>
>> This should not have been replaced. Null is not the smae thing as the
>> empty String. Also this introduces a warning due to ambiguous signatures.
> 
> That was a mistake, but I didn't make it because I thought that
>   "" == null
> was true ;-}.

Ok, thanks

best regards,
Luc

> 
> 
> Best,
> Gilles
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Re: svn commit: r1078734

Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
Hello.

> > Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
> > URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
> > ==============================================================================
> > --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java (original)
> > +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java Mon Mar  7 10:37:52 2011
> > @@ -123,7 +123,9 @@ public class DummyStepInterpolatorTest {
> >          fail("an exception should have been thrown");
> >      } catch (IOException ioe) {
> >          // expected behavior
> > -        assertEquals(0, ioe.getMessage().length());
> > +        // XXX Why was the message supposed to be empty?
> > +        // With the current code it is "org.apache.commons.math.util.Pair".
> > +        // assertEquals(0, ioe.getMessage().length());
> 
> The problem here is that the exception thrown which is an IOException
> built from the empty string in the BadStepInterpolator below is not the
> IOException that is caught here. In fact the IOException caught is
> really a java.io.NotSerializableException which is built with the
> message "org.apache.commons.math.util.Pair" automatically by the
> serialization process in the JVM (at least for Oracle implementation).
> 
> All exceptions must be serializable (this comes from java.lang.Throwable
> implementing the Serializable interface). This was also one reason why
> our Localizable interface had to extends Serializable, so it could be
> used as a field in our exceptions.
> 
> This change added a List<Pair<Localizable, Object[]>> field in
> MathRuntimeException. Pair is not serializable. Adding Serializable to
> the implemented interfaces in Pair does solve the problem (if also the
> change below is reverted, of course) but I don't think it would be wise
> unless we also enforce the two generic parameters of Pair to be
> serializable too. Perhaps we should use a Map<Localizable, Object[]>
> instead ?

No, because a key is unique (so that it won't be possible to add 2 messages
with the same pattern but different values.
I've created a "SerializablePair" (cf. revision 1079545) that seems to solve
the problem.

> The problem also makes me think that we already had a similar bug in
> another part of the exceptions for a long time : the Object or Object[]
> parameters of the exceptions are stored and may not be Serializable too.
> This was never a problem either because the parameters are often simple
> primitive ones (int, double ...) or arrays so they were serializable.
> Perhaps we should change the signature from Object and Object[] to
> Serializable and Serializable[] ?

I'm not fond of imposing "Serializable", as this would forbid user classes
that are not "Serializable" (or force them to make the class "Serializable"
although they don't have any use of that interface).
I think "Object" is more flexible in the sense that users who need
serialization will use "Serializable" classes and it will work...

> >      }
> >  
> >    }
> > @@ -137,7 +139,7 @@ public class DummyStepInterpolatorTest {
> >        }
> >        @Override
> >        protected void doFinalize() throws MathUserException {
> > -          throw new MathUserException((Localizable) null, LocalizedFormats.SIMPLE_MESSAGE, "");
> > +          throw new MathUserException(LocalizedFormats.SIMPLE_MESSAGE, null);
> 
> This should not have been replaced. Null is not the smae thing as the
> empty String. Also this introduces a warning due to ambiguous signatures.

That was a mistake, but I didn't make it because I thought that
  "" == null
was true ;-}.


Best,
Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Re: svn commit: r1078734

Posted by Luc Maisonobe <Lu...@free.fr>.
Le 08/03/2011 21:56, sebb a écrit :
> On 8 March 2011 20:17, Luc Maisonobe <Lu...@free.fr> wrote:
>> Le 07/03/2011 11:37, erans@apache.org a écrit :
>>> Author: erans
>>> Date: Mon Mar  7 10:37:52 2011
>>> New Revision: 1078734
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1078734&view=rev
>>> Log:
>>> MATH-542
>>> "MathRuntimeException" provides two ways for enhancing the information content:
>>> one for localized messages and one for storing "context" objects.
>>> The additional methods have been added to "MathThrowable". Consequently, dummy
>>> implementations were needed in the old "MathRuntimeException" and
>>> "MathException".
>>> Some parts of the tests for old exceptions were removed as they used methods
>>> that were deleted. A call to "MathUserException" in "AbstractContinuousDistribution"
>>> was simplified for the same reason.
>>> "MathUtils" still contained "String" (instead of "Localizable") as argument to
>>> the constructor of a "MathArithmeticException".
>>> I don't know why a test in "DummyStepInterpolatorTest" stopped working. It is now
>>> commented out; please have a look.
>>
>> [snip]
>>
>>
>>> Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
>>> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
>>> ==============================================================================
>>> --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java (original)
>>> +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java Mon Mar  7 10:37:52 2011
>>> @@ -123,7 +123,9 @@ public class DummyStepInterpolatorTest {
>>>          fail("an exception should have been thrown");
>>>      } catch (IOException ioe) {
>>>          // expected behavior
>>> -        assertEquals(0, ioe.getMessage().length());
>>> +        // XXX Why was the message supposed to be empty?
>>> +        // With the current code it is "org.apache.commons.math.util.Pair".
>>> +        // assertEquals(0, ioe.getMessage().length());
>>
>> The problem here is that the exception thrown which is an IOException
>> built from the empty string in the BadStepInterpolator below is not the
>> IOException that is caught here. In fact the IOException caught is
>> really a java.io.NotSerializableException which is built with the
>> message "org.apache.commons.math.util.Pair" automatically by the
>> serialization process in the JVM (at least for Oracle implementation).
>>
>> All exceptions must be serializable (this comes from java.lang.Throwable
>> implementing the Serializable interface). This was also one reason why
>> our Localizable interface had to extends Serializable, so it could be
>> used as a field in our exceptions.
>>
>> This change added a List<Pair<Localizable, Object[]>> field in
>> MathRuntimeException. Pair is not serializable. Adding Serializable to
>> the implemented interfaces in Pair does solve the problem (if also the
>> change below is reverted, of course) but I don't think it would be wise
>> unless we also enforce the two generic parameters of Pair to be
>> serializable too. Perhaps we should use a Map<Localizable, Object[]>
>> instead ?
>>
>> The problem also makes me think that we already had a similar bug in
>> another part of the exceptions for a long time : the Object or Object[]
>> parameters of the exceptions are stored and may not be Serializable too.
>> This was never a problem either because the parameters are often simple
>> primitive ones (int, double ...) or arrays so they were serializable.
>> Perhaps we should change the signature from Object and Object[] to
>> Serializable and Serializable[] ?
>>
> 
> Or make the fields transient?
> 
> That would perhaps cause problems if the Exceptions were ever
> serialised, but can that happen?

At least, it happen with this test. The purpose of the test is to check
the proper handling of a failing deserialization. It seems in the
process the JVM does serialize or deserialize the exception too (I don't
know why).

Another use case I imagine for exception serialization is with
distributed applications (SOA and the like). I guess there may be some
serialization/deserialization at middleware level.

Luc

> 
>>>      }
>>>
>>>    }
>>> @@ -137,7 +139,7 @@ public class DummyStepInterpolatorTest {
>>>        }
>>>        @Override
>>>        protected void doFinalize() throws MathUserException {
>>> -          throw new MathUserException((Localizable) null, LocalizedFormats.SIMPLE_MESSAGE, "");
>>> +          throw new MathUserException(LocalizedFormats.SIMPLE_MESSAGE, null);
>>
>> This should not have been replaced. Null is not the smae thing as the
>> empty String. Also this introduces a warning due to ambiguous signatures.
>>
>> Luc
>>
>>>        }
>>>    }
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Re: svn commit: r1078734

Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
Hi.

> >>> [...]
> >>> You are right, I am stupid. So we have to check for serializable.
> >>
> >> I don't see why: The serialization will work provided all "Object"
> >> arguments are "Serializable"; it is the user's code responsibility to not
> >> try serializing the exception when it knows that it contains a
> >> non-serializable object.
> >> If the exceptions generated from CM contain only serializable objects
> >> (which is the case now), then we've done our part.
> > 
> > Yes, but it might not be always directly obvious. It's always annoying, if 
> > in a client/server scenario an error occurs and suddenly cannot even 
> > reported to the client. That's why I proposed the customized 
> > writeObject/readObject for MathRE. The thrown exception should make it under 
> > any circumstances over the wire, even if it means that unserializable 
> > objects are nulled or replaced with a String representation. Otherwise the 
> > client simply gets an error and no-one can tell why. However, this is an 
> > action only for the serialization process. Or ensure - as already proposed 
> > in this thread - that only serializable types can be added by using an 
> > appropriate method/type signature.
> 
> Since in this case a complete roundtrip serialization/deserialization
> occurs, I think we should convert to null non-serializable objects at
> the serialization step as you propose.

I didn't get why they should be set to "null".
In revision 1080231, I've replaced non-Serializable objects by a String
indicating that the given class cannot be serialized.

[I had to remove the "final" modifier on the "messages" and "context" fields
because they must be initialized in the "readObject" method...]


Regards,
Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Re: svn commit: r1078734

Posted by Luc Maisonobe <Lu...@free.fr>.
Le 09/03/2011 16:55, Jörg Schaible a écrit :
> Hi Gilles,
> 
> Gilles Sadowski wrote:
> 
>> On Wed, Mar 09, 2011 at 03:00:07PM +0100, Luc Maisonobe wrote:
>>> Le 09/03/2011 13:59, Gilles Sadowski a écrit :
>>>> Hi.
>>>>
>>>>>>> [...]
>>>>>>>
>>>>>>> Or make the fields transient?
>>>>>>>
>>>>>>> That would perhaps cause problems if the Exceptions were ever
>>>>>>> serialised, but can that happen?
>>>>>>
>>>>>> Yes, it's a typical JEE scenario and I cannot say how often I cursed
>>>>>> Sun for stuffing an unserializable object into
>>>>>> NamingException.setResolvedObject within their LDAP implementation
>>>>>> ...
>>>>>>
>>>>>> Actually the MathRE should contain a writeObject implementation that
>>>>>> replaces any non-serializable object in that array with some kind of
>>>>>> replacement (e.g. with its String representation). Otherwise the
>>>>>> MathRE will not reach its destination and all the localization was
>>>>>> for nothing.
>>>>>
>>>>> That's a good idea. We could even do that replacement directly at
>>>>> construction and never store the Object themselves, regardless of
>>>>> their status with respect to serialization.
>>>>
>>>> Do you mean storing only the String representation of the arguments?
>>>> Wouldn't that defeat the purpose of the map feature (which was to allow
>>>> any kind of objects to be stored and retrieved)?
>>>
>>> You are right, I am stupid. So we have to check for serializable.
>>
>> I don't see why: The serialization will work provided all "Object"
>> arguments are "Serializable"; it is the user's code responsibility to not
>> try serializing the exception when it knows that it contains a
>> non-serializable object.
>> If the exceptions generated from CM contain only serializable objects
>> (which is the case now), then we've done our part.
> 
> Yes, but it might not be always directly obvious. It's always annoying, if 
> in a client/server scenario an error occurs and suddenly cannot even 
> reported to the client. That's why I proposed the customized 
> writeObject/readObject for MathRE. The thrown exception should make it under 
> any circumstances over the wire, even if it means that unserializable 
> objects are nulled or replaced with a String representation. Otherwise the 
> client simply gets an error and no-one can tell why. However, this is an 
> action only for the serialization process. Or ensure - as already proposed 
> in this thread - that only serializable types can be added by using an 
> appropriate method/type signature.

Since in this case a complete roundtrip serialization/deserialization
occurs, I think we should convert to null non-serializable objects at
the serialization step as you propose.

Luc

> 
> - Jörg
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Re: svn commit: r1078734

Posted by Jörg Schaible <jo...@scalaris.com>.
Hi Gilles,

Gilles Sadowski wrote:

> On Wed, Mar 09, 2011 at 03:00:07PM +0100, Luc Maisonobe wrote:
>> Le 09/03/2011 13:59, Gilles Sadowski a écrit :
>> > Hi.
>> > 
>> >>>> [...]
>> >>>>
>> >>>> Or make the fields transient?
>> >>>>
>> >>>> That would perhaps cause problems if the Exceptions were ever
>> >>>> serialised, but can that happen?
>> >>>
>> >>> Yes, it's a typical JEE scenario and I cannot say how often I cursed
>> >>> Sun for stuffing an unserializable object into
>> >>> NamingException.setResolvedObject within their LDAP implementation
>> >>> ...
>> >>>
>> >>> Actually the MathRE should contain a writeObject implementation that
>> >>> replaces any non-serializable object in that array with some kind of
>> >>> replacement (e.g. with its String representation). Otherwise the
>> >>> MathRE will not reach its destination and all the localization was
>> >>> for nothing.
>> >>
>> >> That's a good idea. We could even do that replacement directly at
>> >> construction and never store the Object themselves, regardless of
>> >> their status with respect to serialization.
>> > 
>> > Do you mean storing only the String representation of the arguments?
>> > Wouldn't that defeat the purpose of the map feature (which was to allow
>> > any kind of objects to be stored and retrieved)?
>> 
>> You are right, I am stupid. So we have to check for serializable.
> 
> I don't see why: The serialization will work provided all "Object"
> arguments are "Serializable"; it is the user's code responsibility to not
> try serializing the exception when it knows that it contains a
> non-serializable object.
> If the exceptions generated from CM contain only serializable objects
> (which is the case now), then we've done our part.

Yes, but it might not be always directly obvious. It's always annoying, if 
in a client/server scenario an error occurs and suddenly cannot even 
reported to the client. That's why I proposed the customized 
writeObject/readObject for MathRE. The thrown exception should make it under 
any circumstances over the wire, even if it means that unserializable 
objects are nulled or replaced with a String representation. Otherwise the 
client simply gets an error and no-one can tell why. However, this is an 
action only for the serialization process. Or ensure - as already proposed 
in this thread - that only serializable types can be added by using an 
appropriate method/type signature.

- Jörg



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Re: svn commit: r1078734

Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
On Wed, Mar 09, 2011 at 03:00:07PM +0100, Luc Maisonobe wrote:
> Le 09/03/2011 13:59, Gilles Sadowski a écrit :
> > Hi.
> > 
> >>>> [...]
> >>>>
> >>>> Or make the fields transient?
> >>>>
> >>>> That would perhaps cause problems if the Exceptions were ever
> >>>> serialised, but can that happen?
> >>>
> >>> Yes, it's a typical JEE scenario and I cannot say how often I cursed Sun for 
> >>> stuffing an unserializable object into NamingException.setResolvedObject 
> >>> within their LDAP implementation ...
> >>>
> >>> Actually the MathRE should contain a writeObject implementation that 
> >>> replaces any non-serializable object in that array with some kind of 
> >>> replacement (e.g. with its String representation). Otherwise the MathRE will 
> >>> not reach its destination and all the localization was for nothing.
> >>
> >> That's a good idea. We could even do that replacement directly at
> >> construction and never store the Object themselves, regardless of their
> >> status with respect to serialization.
> > 
> > Do you mean storing only the String representation of the arguments?
> > Wouldn't that defeat the purpose of the map feature (which was to allow any
> > kind of objects to be stored and retrieved)?
> 
> You are right, I am stupid. So we have to check for serializable.

I don't see why: The serialization will work provided all "Object" arguments
are "Serializable"; it is the user's code responsibility to not try
serializing the exception when it knows that it contains a non-serializable
object.
If the exceptions generated from CM contain only serializable objects (which
is the case now), then we've done our part.


Best,
Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Re: svn commit: r1078734

Posted by Luc Maisonobe <Lu...@free.fr>.
Le 09/03/2011 13:59, Gilles Sadowski a écrit :
> Hi.
> 
>>>> [...]
>>>>
>>>> Or make the fields transient?
>>>>
>>>> That would perhaps cause problems if the Exceptions were ever
>>>> serialised, but can that happen?
>>>
>>> Yes, it's a typical JEE scenario and I cannot say how often I cursed Sun for 
>>> stuffing an unserializable object into NamingException.setResolvedObject 
>>> within their LDAP implementation ...
>>>
>>> Actually the MathRE should contain a writeObject implementation that 
>>> replaces any non-serializable object in that array with some kind of 
>>> replacement (e.g. with its String representation). Otherwise the MathRE will 
>>> not reach its destination and all the localization was for nothing.
>>
>> That's a good idea. We could even do that replacement directly at
>> construction and never store the Object themselves, regardless of their
>> status with respect to serialization.
> 
> Do you mean storing only the String representation of the arguments?
> Wouldn't that defeat the purpose of the map feature (which was to allow any
> kind of objects to be stored and retrieved)?

You are right, I am stupid. So we have to check for serializable.

Luc

> 
> 
> Best regards,
> Gilles
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Re: svn commit: r1078734

Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
Hi.

> >> [...]
> >>
> >> Or make the fields transient?
> >>
> >> That would perhaps cause problems if the Exceptions were ever
> >> serialised, but can that happen?
> > 
> > Yes, it's a typical JEE scenario and I cannot say how often I cursed Sun for 
> > stuffing an unserializable object into NamingException.setResolvedObject 
> > within their LDAP implementation ...
> > 
> > Actually the MathRE should contain a writeObject implementation that 
> > replaces any non-serializable object in that array with some kind of 
> > replacement (e.g. with its String representation). Otherwise the MathRE will 
> > not reach its destination and all the localization was for nothing.
> 
> That's a good idea. We could even do that replacement directly at
> construction and never store the Object themselves, regardless of their
> status with respect to serialization.

Do you mean storing only the String representation of the arguments?
Wouldn't that defeat the purpose of the map feature (which was to allow any
kind of objects to be stored and retrieved)?


Best regards,
Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Re: svn commit: r1078734

Posted by Luc Maisonobe <Lu...@free.fr>.
Hi,

Le 08/03/2011 23:51, Jörg Schaible a écrit :
> sebb wrote:
> 
>> On 8 March 2011 20:17, Luc Maisonobe <Lu...@free.fr> wrote:
>>> Le 07/03/2011 11:37, erans@apache.org a écrit :
>>>> Author: erans
>>>> Date: Mon Mar  7 10:37:52 2011
>>>> New Revision: 1078734
>>>>
>>>> URL: http://svn.apache.org/viewvc?rev=1078734&view=rev
>>>> Log:
>>>> MATH-542
>>>> "MathRuntimeException" provides two ways for enhancing the information
>>>> content: one for localized messages and one for storing "context"
>>>> objects. The additional methods have been added to "MathThrowable".
>>>> Consequently, dummy implementations were needed in the old
>>>> "MathRuntimeException" and "MathException".
>>>> Some parts of the tests for old exceptions were removed as they used
>>>> methods that were deleted. A call to "MathUserException" in
>>>> "AbstractContinuousDistribution" was simplified for the same reason.
>>>> "MathUtils" still contained "String" (instead of "Localizable") as
>>>> argument to the constructor of a "MathArithmeticException".
>>>> I don't know why a test in "DummyStepInterpolatorTest" stopped working.
>>>> It is now commented out; please have a look.
>>>
>>> [snip]
>>>
>>>
>>>> Modified:
>>>>
> commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
>>>> URL:
>>>>
> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
>>>>
> ==============================================================================
>>>> ---
>>>>
> commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
>>>> (original) +++
>>>>
> commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
>>>> Mon Mar  7 10:37:52 2011 @@ -123,7 +123,9 @@ public class
>>>> DummyStepInterpolatorTest { fail("an exception should have been
>>>> thrown"); } catch (IOException ioe) { // expected behavior -       
>>>> assertEquals(0, ioe.getMessage().length()); +        // XXX Why was the
>>>> message supposed to be empty? +        // With the current code it is
>>>> "org.apache.commons.math.util.Pair". +        // assertEquals(0,
>>>> ioe.getMessage().length());
>>>
>>> The problem here is that the exception thrown which is an IOException
>>> built from the empty string in the BadStepInterpolator below is not the
>>> IOException that is caught here. In fact the IOException caught is
>>> really a java.io.NotSerializableException which is built with the
>>> message "org.apache.commons.math.util.Pair" automatically by the
>>> serialization process in the JVM (at least for Oracle implementation).
>>>
>>> All exceptions must be serializable (this comes from java.lang.Throwable
>>> implementing the Serializable interface). This was also one reason why
>>> our Localizable interface had to extends Serializable, so it could be
>>> used as a field in our exceptions.
>>>
>>> This change added a List<Pair<Localizable, Object[]>> field in
>>> MathRuntimeException. Pair is not serializable. Adding Serializable to
>>> the implemented interfaces in Pair does solve the problem (if also the
>>> change below is reverted, of course) but I don't think it would be wise
>>> unless we also enforce the two generic parameters of Pair to be
>>> serializable too. Perhaps we should use a Map<Localizable, Object[]>
>>> instead ?
>>>
>>> The problem also makes me think that we already had a similar bug in
>>> another part of the exceptions for a long time : the Object or Object[]
>>> parameters of the exceptions are stored and may not be Serializable too.
>>> This was never a problem either because the parameters are often simple
>>> primitive ones (int, double ...) or arrays so they were serializable.
>>> Perhaps we should change the signature from Object and Object[] to
>>> Serializable and Serializable[] ?
>>>
>>
>> Or make the fields transient?
>>
>> That would perhaps cause problems if the Exceptions were ever
>> serialised, but can that happen?
> 
> Yes, it's a typical JEE scenario and I cannot say how often I cursed Sun for 
> stuffing an unserializable object into NamingException.setResolvedObject 
> within their LDAP implementation ...
> 
> Actually the MathRE should contain a writeObject implementation that 
> replaces any non-serializable object in that array with some kind of 
> replacement (e.g. with its String representation). Otherwise the MathRE will 
> not reach its destination and all the localization was for nothing.

That's a good idea. We could even do that replacement directly at
construction and never store the Object themselves, regardless of their
status with respect to serialization.

Thanks Jörg

> 
> However, with a writeObject/readObject pair, such a field can be made 
> transparent, if the objects are put directly into the object streams.
> 
> Note, that anything of this requires a change of the serialVersionUID.
> 
> - Jörg
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Re: svn commit: r1078734

Posted by Jörg Schaible <jo...@gmx.de>.
sebb wrote:

> On 8 March 2011 20:17, Luc Maisonobe <Lu...@free.fr> wrote:
>> Le 07/03/2011 11:37, erans@apache.org a écrit :
>>> Author: erans
>>> Date: Mon Mar  7 10:37:52 2011
>>> New Revision: 1078734
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1078734&view=rev
>>> Log:
>>> MATH-542
>>> "MathRuntimeException" provides two ways for enhancing the information
>>> content: one for localized messages and one for storing "context"
>>> objects. The additional methods have been added to "MathThrowable".
>>> Consequently, dummy implementations were needed in the old
>>> "MathRuntimeException" and "MathException".
>>> Some parts of the tests for old exceptions were removed as they used
>>> methods that were deleted. A call to "MathUserException" in
>>> "AbstractContinuousDistribution" was simplified for the same reason.
>>> "MathUtils" still contained "String" (instead of "Localizable") as
>>> argument to the constructor of a "MathArithmeticException".
>>> I don't know why a test in "DummyStepInterpolatorTest" stopped working.
>>> It is now commented out; please have a look.
>>
>> [snip]
>>
>>
>>> Modified:
>>> 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
>>> URL:
>>> 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
>>> 
==============================================================================
>>> ---
>>> 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
>>> (original) +++
>>> 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
>>> Mon Mar  7 10:37:52 2011 @@ -123,7 +123,9 @@ public class
>>> DummyStepInterpolatorTest { fail("an exception should have been
>>> thrown"); } catch (IOException ioe) { // expected behavior -       
>>> assertEquals(0, ioe.getMessage().length()); +        // XXX Why was the
>>> message supposed to be empty? +        // With the current code it is
>>> "org.apache.commons.math.util.Pair". +        // assertEquals(0,
>>> ioe.getMessage().length());
>>
>> The problem here is that the exception thrown which is an IOException
>> built from the empty string in the BadStepInterpolator below is not the
>> IOException that is caught here. In fact the IOException caught is
>> really a java.io.NotSerializableException which is built with the
>> message "org.apache.commons.math.util.Pair" automatically by the
>> serialization process in the JVM (at least for Oracle implementation).
>>
>> All exceptions must be serializable (this comes from java.lang.Throwable
>> implementing the Serializable interface). This was also one reason why
>> our Localizable interface had to extends Serializable, so it could be
>> used as a field in our exceptions.
>>
>> This change added a List<Pair<Localizable, Object[]>> field in
>> MathRuntimeException. Pair is not serializable. Adding Serializable to
>> the implemented interfaces in Pair does solve the problem (if also the
>> change below is reverted, of course) but I don't think it would be wise
>> unless we also enforce the two generic parameters of Pair to be
>> serializable too. Perhaps we should use a Map<Localizable, Object[]>
>> instead ?
>>
>> The problem also makes me think that we already had a similar bug in
>> another part of the exceptions for a long time : the Object or Object[]
>> parameters of the exceptions are stored and may not be Serializable too.
>> This was never a problem either because the parameters are often simple
>> primitive ones (int, double ...) or arrays so they were serializable.
>> Perhaps we should change the signature from Object and Object[] to
>> Serializable and Serializable[] ?
>>
> 
> Or make the fields transient?
> 
> That would perhaps cause problems if the Exceptions were ever
> serialised, but can that happen?

Yes, it's a typical JEE scenario and I cannot say how often I cursed Sun for 
stuffing an unserializable object into NamingException.setResolvedObject 
within their LDAP implementation ...

Actually the MathRE should contain a writeObject implementation that 
replaces any non-serializable object in that array with some kind of 
replacement (e.g. with its String representation). Otherwise the MathRE will 
not reach its destination and all the localization was for nothing.

However, with a writeObject/readObject pair, such a field can be made 
transparent, if the objects are put directly into the object streams.

Note, that anything of this requires a change of the serialVersionUID.

- Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] Re: svn commit: r1078734

Posted by sebb <se...@gmail.com>.
On 8 March 2011 20:17, Luc Maisonobe <Lu...@free.fr> wrote:
> Le 07/03/2011 11:37, erans@apache.org a écrit :
>> Author: erans
>> Date: Mon Mar  7 10:37:52 2011
>> New Revision: 1078734
>>
>> URL: http://svn.apache.org/viewvc?rev=1078734&view=rev
>> Log:
>> MATH-542
>> "MathRuntimeException" provides two ways for enhancing the information content:
>> one for localized messages and one for storing "context" objects.
>> The additional methods have been added to "MathThrowable". Consequently, dummy
>> implementations were needed in the old "MathRuntimeException" and
>> "MathException".
>> Some parts of the tests for old exceptions were removed as they used methods
>> that were deleted. A call to "MathUserException" in "AbstractContinuousDistribution"
>> was simplified for the same reason.
>> "MathUtils" still contained "String" (instead of "Localizable") as argument to
>> the constructor of a "MathArithmeticException".
>> I don't know why a test in "DummyStepInterpolatorTest" stopped working. It is now
>> commented out; please have a look.
>
> [snip]
>
>
>> Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
>> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
>> ==============================================================================
>> --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java (original)
>> +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java Mon Mar  7 10:37:52 2011
>> @@ -123,7 +123,9 @@ public class DummyStepInterpolatorTest {
>>          fail("an exception should have been thrown");
>>      } catch (IOException ioe) {
>>          // expected behavior
>> -        assertEquals(0, ioe.getMessage().length());
>> +        // XXX Why was the message supposed to be empty?
>> +        // With the current code it is "org.apache.commons.math.util.Pair".
>> +        // assertEquals(0, ioe.getMessage().length());
>
> The problem here is that the exception thrown which is an IOException
> built from the empty string in the BadStepInterpolator below is not the
> IOException that is caught here. In fact the IOException caught is
> really a java.io.NotSerializableException which is built with the
> message "org.apache.commons.math.util.Pair" automatically by the
> serialization process in the JVM (at least for Oracle implementation).
>
> All exceptions must be serializable (this comes from java.lang.Throwable
> implementing the Serializable interface). This was also one reason why
> our Localizable interface had to extends Serializable, so it could be
> used as a field in our exceptions.
>
> This change added a List<Pair<Localizable, Object[]>> field in
> MathRuntimeException. Pair is not serializable. Adding Serializable to
> the implemented interfaces in Pair does solve the problem (if also the
> change below is reverted, of course) but I don't think it would be wise
> unless we also enforce the two generic parameters of Pair to be
> serializable too. Perhaps we should use a Map<Localizable, Object[]>
> instead ?
>
> The problem also makes me think that we already had a similar bug in
> another part of the exceptions for a long time : the Object or Object[]
> parameters of the exceptions are stored and may not be Serializable too.
> This was never a problem either because the parameters are often simple
> primitive ones (int, double ...) or arrays so they were serializable.
> Perhaps we should change the signature from Object and Object[] to
> Serializable and Serializable[] ?
>

Or make the fields transient?

That would perhaps cause problems if the Exceptions were ever
serialised, but can that happen?

>>      }
>>
>>    }
>> @@ -137,7 +139,7 @@ public class DummyStepInterpolatorTest {
>>        }
>>        @Override
>>        protected void doFinalize() throws MathUserException {
>> -          throw new MathUserException((Localizable) null, LocalizedFormats.SIMPLE_MESSAGE, "");
>> +          throw new MathUserException(LocalizedFormats.SIMPLE_MESSAGE, null);
>
> This should not have been replaced. Null is not the smae thing as the
> empty String. Also this introduces a warning due to ambiguous signatures.
>
> Luc
>
>>        }
>>    }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[math] Re: svn commit: r1078734

Posted by Luc Maisonobe <Lu...@free.fr>.
Le 07/03/2011 11:37, erans@apache.org a écrit :
> Author: erans
> Date: Mon Mar  7 10:37:52 2011
> New Revision: 1078734
> 
> URL: http://svn.apache.org/viewvc?rev=1078734&view=rev
> Log:
> MATH-542
> "MathRuntimeException" provides two ways for enhancing the information content:
> one for localized messages and one for storing "context" objects.
> The additional methods have been added to "MathThrowable". Consequently, dummy
> implementations were needed in the old "MathRuntimeException" and
> "MathException".
> Some parts of the tests for old exceptions were removed as they used methods
> that were deleted. A call to "MathUserException" in "AbstractContinuousDistribution"
> was simplified for the same reason.
> "MathUtils" still contained "String" (instead of "Localizable") as argument to
> the constructor of a "MathArithmeticException".
> I don't know why a test in "DummyStepInterpolatorTest" stopped working. It is now
> commented out; please have a look.

[snip]


> Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
> ==============================================================================
> --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java (original)
> +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java Mon Mar  7 10:37:52 2011
> @@ -123,7 +123,9 @@ public class DummyStepInterpolatorTest {
>          fail("an exception should have been thrown");
>      } catch (IOException ioe) {
>          // expected behavior
> -        assertEquals(0, ioe.getMessage().length());
> +        // XXX Why was the message supposed to be empty?
> +        // With the current code it is "org.apache.commons.math.util.Pair".
> +        // assertEquals(0, ioe.getMessage().length());

The problem here is that the exception thrown which is an IOException
built from the empty string in the BadStepInterpolator below is not the
IOException that is caught here. In fact the IOException caught is
really a java.io.NotSerializableException which is built with the
message "org.apache.commons.math.util.Pair" automatically by the
serialization process in the JVM (at least for Oracle implementation).

All exceptions must be serializable (this comes from java.lang.Throwable
implementing the Serializable interface). This was also one reason why
our Localizable interface had to extends Serializable, so it could be
used as a field in our exceptions.

This change added a List<Pair<Localizable, Object[]>> field in
MathRuntimeException. Pair is not serializable. Adding Serializable to
the implemented interfaces in Pair does solve the problem (if also the
change below is reverted, of course) but I don't think it would be wise
unless we also enforce the two generic parameters of Pair to be
serializable too. Perhaps we should use a Map<Localizable, Object[]>
instead ?

The problem also makes me think that we already had a similar bug in
another part of the exceptions for a long time : the Object or Object[]
parameters of the exceptions are stored and may not be Serializable too.
This was never a problem either because the parameters are often simple
primitive ones (int, double ...) or arrays so they were serializable.
Perhaps we should change the signature from Object and Object[] to
Serializable and Serializable[] ?


>      }
>  
>    }
> @@ -137,7 +139,7 @@ public class DummyStepInterpolatorTest {
>        }
>        @Override
>        protected void doFinalize() throws MathUserException {
> -          throw new MathUserException((Localizable) null, LocalizedFormats.SIMPLE_MESSAGE, "");
> +          throw new MathUserException(LocalizedFormats.SIMPLE_MESSAGE, null);

This should not have been replaced. Null is not the smae thing as the
empty String. Also this introduces a warning due to ambiguous signatures.

Luc

>        }
>    }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org