commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r712187 - in /commons/proper/math/branches/MATH_2_0/src: java/org/apache/commons/math/ java/org/apache/commons/math/ode/nonstiff/ java/org/apache/commons/math/ode/sampling/ java/org/apache/commons/math/random/ test/org/apache/commons/math/o...
Date Fri, 07 Nov 2008 16:32:09 GMT
Author: luc
Date: Fri Nov  7 08:31:58 2008
New Revision: 712187

URL: http://svn.apache.org/viewvc?rev=712187&view=rev
Log:
allow chained IOExceptions even before Java 6

Modified:
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MathRuntimeException.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolator.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/MultistepStepInterpolator.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaStepInterpolator.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/sampling/DummyStepInterpolator.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
    commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MathRuntimeException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MathRuntimeException.java?rev=712187&r1=712186&r2=712187&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MathRuntimeException.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/MathRuntimeException.java
Fri Nov  7 08:31:58 2008
@@ -17,6 +17,7 @@
 package org.apache.commons.math;
 
 import java.io.EOFException;
+import java.io.IOException;
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.text.MessageFormat;
@@ -249,6 +250,22 @@
     }
 
     /**
+     * Constructs a new <code>IOException</code> with specified nested
+     * <code>Throwable</code> root cause.
+     * <p>This factory method allows chaining of other exceptions within an
+     * <code>IOException</code> even for Java 5. The constructor for
+     * <code>IOException</code> with a cause parameter was introduced only
+     * with Java 6.</p>
+     * @param rootCause the exception or error that caused this exception
+     * to be thrown.
+     */
+    public static IOException createIOException(final Throwable rootCause) {
+        IOException ioe = new IOException(rootCause.getLocalizedMessage());
+        ioe.initCause(rootCause);
+        return ioe;
+    }
+
+    /**
      * Constructs a new <code>IllegalArgumentException</code> with specified
formatted detail message.
      * Message formatting is delegated to {@link java.text.MessageFormat}.
      * @param pattern format specifier

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolator.java?rev=712187&r1=712186&r2=712187&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolator.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolator.java
Fri Nov  7 08:31:58 2008
@@ -21,6 +21,7 @@
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.ode.DerivativeException;
 import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
 import org.apache.commons.math.ode.sampling.StepInterpolator;
@@ -250,7 +251,7 @@
       // save the local attributes
       finalizeStep();
     } catch (DerivativeException e) {
-      throw new IOException(e.getMessage());
+      throw MathRuntimeException.createIOException(e);
     }
     out.writeInt(currentState.length);
     for (int i = 0; i < currentState.length; ++i) {

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java?rev=712187&r1=712186&r2=712187&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java
Fri Nov  7 08:31:58 2008
@@ -21,6 +21,7 @@
 import java.io.ObjectOutput;
 import java.io.IOException;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.ode.DerivativeException;
 import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
 import org.apache.commons.math.ode.sampling.StepInterpolator;
@@ -392,7 +393,7 @@
       // we can now set the interpolated time and state
       setInterpolatedTime(t);
     } catch (DerivativeException e) {
-      throw new IOException(e.getMessage());
+      throw MathRuntimeException.createIOException(e);
     }
 
   }

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/MultistepStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/MultistepStepInterpolator.java?rev=712187&r1=712186&r2=712187&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/MultistepStepInterpolator.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/MultistepStepInterpolator.java
Fri Nov  7 08:31:58 2008
@@ -21,6 +21,7 @@
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.ode.DerivativeException;
 import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
 
@@ -157,7 +158,7 @@
             // we can now set the interpolated time and state
             setInterpolatedTime(t);
         } catch (DerivativeException e) {
-            throw new IOException(e.getMessage());
+            throw MathRuntimeException.createIOException(e);
         }
 
     }

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaStepInterpolator.java?rev=712187&r1=712186&r2=712187&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaStepInterpolator.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaStepInterpolator.java
Fri Nov  7 08:31:58 2008
@@ -21,6 +21,7 @@
 import java.io.ObjectOutput;
 import java.io.IOException;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.ode.DerivativeException;
 import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
 import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
@@ -165,7 +166,7 @@
       // we can now set the interpolated time and state
       setInterpolatedTime(t);
     } catch (DerivativeException e) {
-      throw new IOException(e.getMessage());
+      throw MathRuntimeException.createIOException(e);
     }
 
   }

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java?rev=712187&r1=712186&r2=712187&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java
Fri Nov  7 08:31:58 2008
@@ -21,6 +21,7 @@
 import java.io.ObjectOutput;
 import java.io.IOException;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.ode.DerivativeException;
 import org.apache.commons.math.ode.FirstOrderIntegrator;
 import org.apache.commons.math.ode.SecondOrderIntegrator;
@@ -369,7 +370,7 @@
     try {
       finalizeStep();
     } catch (DerivativeException e) {
-      throw new IOException(e.getMessage());
+      throw MathRuntimeException.createIOException(e);
     }
 
   }

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/sampling/DummyStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/sampling/DummyStepInterpolator.java?rev=712187&r1=712186&r2=712187&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/sampling/DummyStepInterpolator.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/sampling/DummyStepInterpolator.java
Fri Nov  7 08:31:58 2008
@@ -21,6 +21,7 @@
 import java.io.ObjectOutput;
 import java.io.IOException;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.ode.DerivativeException;
 import org.apache.commons.math.ode.nonstiff.EmbeddedRungeKuttaIntegrator;
 
@@ -119,7 +120,7 @@
       // we can now set the interpolated time and state
       setInterpolatedTime(t);
     } catch (DerivativeException e) {
-      throw new IOException(e.getMessage());
+      throw MathRuntimeException.createIOException(e);
     }
 
   }

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java?rev=712187&r1=712186&r2=712187&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
Fri Nov  7 08:31:58 2008
@@ -136,7 +136,7 @@
                 // don't wrap RuntimeExceptions
                 throw rte;
             } catch (Exception e) {
-                throw new IOException(e.getMessage());
+                throw MathRuntimeException.createIOException(e);
             }
             if (sampleStats.getN() == 0) {
                 throw MathRuntimeException.createEOFException("URL {0} contains no data",
@@ -175,7 +175,7 @@
                 // don't wrap RuntimeExceptions
                 throw rte;
             } catch (Exception e) {
-                throw new IOException(e.getMessage());
+                throw MathRuntimeException.createIOException(e);
             }
             in = new BufferedReader(new FileReader(file));
             fillBinStats(in);
@@ -376,7 +376,7 @@
             // don't wrap RuntimeExceptions
             throw rte;
         } catch (Exception e) {
-            throw new IOException(e.getMessage());
+            throw MathRuntimeException.createIOException(e);
         }
 
         // Assign upperBounds based on bin counts

Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java?rev=712187&r1=712186&r2=712187&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
Fri Nov  7 08:31:58 2008
@@ -120,7 +120,7 @@
         fail("an exception should have been thrown");
     } catch (IOException ioe) {
         // expected behavior
-        assertNull(ioe.getMessage());
+        assertEquals(0, ioe.getMessage().length());
     } catch (Exception e) {
         fail("wrong exception caught");
     }
@@ -166,7 +166,7 @@
         fail("an exception should have been thrown");
     } catch (IOException ioe) {
         // expected behavior
-        assertNull(ioe.getMessage());
+        assertEquals(0, ioe.getMessage().length());
     } catch (Exception e) {
         fail("wrong exception caught");
     }



Mime
View raw message