From b1592908df84ddbea649933024af8d44b2b0644f Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Fri, 7 Nov 2008 14:48:13 +0000 Subject: [PATCH] leverage null pointer handling, exception classes can be built using null arguments arrays which are automatically converted to zero-sized arrays to prevent null pointer exceptions git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_0@712142 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/math/ConvergenceException.java | 2 +- .../math/geometry/CardanEulerSingularityException.java | 2 +- .../math/linear/RankDeficientMatrixException.java | 2 +- .../commons/math/linear/SingularMatrixException.java | 2 +- .../random/NotPositiveDefiniteMatrixException.java | 2 +- .../commons/math/MathConfigurationExceptionTest.java | 2 +- .../org/apache/commons/math/MathExceptionTest.java | 10 +++++----- .../math/linear/InvalidMatrixExceptionTest.java | 2 +- .../commons/math/linear/MatrixIndexExceptionTest.java | 2 +- .../apache/commons/math/linear/RealMatrixImplTest.java | 2 +- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/java/org/apache/commons/math/ConvergenceException.java b/src/java/org/apache/commons/math/ConvergenceException.java index f293fa948..c744c801c 100644 --- a/src/java/org/apache/commons/math/ConvergenceException.java +++ b/src/java/org/apache/commons/math/ConvergenceException.java @@ -31,7 +31,7 @@ public class ConvergenceException extends MathException { * Default constructor. */ public ConvergenceException() { - super("Convergence failed", new Object[0]); + super("Convergence failed", null); } /** diff --git a/src/java/org/apache/commons/math/geometry/CardanEulerSingularityException.java b/src/java/org/apache/commons/math/geometry/CardanEulerSingularityException.java index d3b34270b..702ad3f8f 100644 --- a/src/java/org/apache/commons/math/geometry/CardanEulerSingularityException.java +++ b/src/java/org/apache/commons/math/geometry/CardanEulerSingularityException.java @@ -35,7 +35,7 @@ public class CardanEulerSingularityException * if false it is related to EulerAngles */ public CardanEulerSingularityException(boolean isCardan) { - super(isCardan ? "Cardan angles singularity" : "Euler angles singularity", new Object[0]); + super(isCardan ? "Cardan angles singularity" : "Euler angles singularity", null); } /** Serializable version identifier */ diff --git a/src/java/org/apache/commons/math/linear/RankDeficientMatrixException.java b/src/java/org/apache/commons/math/linear/RankDeficientMatrixException.java index e3b7159ee..94f063eb7 100644 --- a/src/java/org/apache/commons/math/linear/RankDeficientMatrixException.java +++ b/src/java/org/apache/commons/math/linear/RankDeficientMatrixException.java @@ -31,7 +31,7 @@ public class RankDeficientMatrixException extends InvalidMatrixException { * Construct an exception with a default message. */ public RankDeficientMatrixException() { - super("matrix is rank-deficient", new Object[0]); + super("matrix is rank-deficient", null); } } diff --git a/src/java/org/apache/commons/math/linear/SingularMatrixException.java b/src/java/org/apache/commons/math/linear/SingularMatrixException.java index a526f6bde..e1c160e99 100644 --- a/src/java/org/apache/commons/math/linear/SingularMatrixException.java +++ b/src/java/org/apache/commons/math/linear/SingularMatrixException.java @@ -31,7 +31,7 @@ public class SingularMatrixException extends InvalidMatrixException { * Construct an exception with a default message. */ public SingularMatrixException() { - super("matrix is singular", new Object[0]); + super("matrix is singular", null); } } diff --git a/src/java/org/apache/commons/math/random/NotPositiveDefiniteMatrixException.java b/src/java/org/apache/commons/math/random/NotPositiveDefiniteMatrixException.java index 8b7ae9ac4..581dd7a2f 100644 --- a/src/java/org/apache/commons/math/random/NotPositiveDefiniteMatrixException.java +++ b/src/java/org/apache/commons/math/random/NotPositiveDefiniteMatrixException.java @@ -36,7 +36,7 @@ public class NotPositiveDefiniteMatrixException extends MathException { * build an exception with a default message. */ public NotPositiveDefiniteMatrixException() { - super("not positive definite matrix", new Object[0]); + super("not positive definite matrix", null); } } diff --git a/src/test/org/apache/commons/math/MathConfigurationExceptionTest.java b/src/test/org/apache/commons/math/MathConfigurationExceptionTest.java index 340e5a345..6f4cc7659 100644 --- a/src/test/org/apache/commons/math/MathConfigurationExceptionTest.java +++ b/src/test/org/apache/commons/math/MathConfigurationExceptionTest.java @@ -30,7 +30,7 @@ public class MathConfigurationExceptionTest extends TestCase { MathConfigurationException ex = new MathConfigurationException(); assertNull(ex.getCause()); assertNull(ex.getMessage()); - assertNull(ex.getMessage(Locale.FRENCH)); + assertEquals(0, ex.getMessage(Locale.FRENCH).length()); } public void testConstructorPatternArguments(){ diff --git a/src/test/org/apache/commons/math/MathExceptionTest.java b/src/test/org/apache/commons/math/MathExceptionTest.java index cbb3ab455..ad25f3887 100644 --- a/src/test/org/apache/commons/math/MathExceptionTest.java +++ b/src/test/org/apache/commons/math/MathExceptionTest.java @@ -33,7 +33,7 @@ public class MathExceptionTest extends TestCase { MathException ex = new MathException(); assertNull(ex.getCause()); assertNull(ex.getMessage()); - assertNull(ex.getMessage(Locale.FRENCH)); + assertEquals(0, ex.getMessage(Locale.FRENCH).length()); } public void testConstructorPatternArguments(){ @@ -79,8 +79,8 @@ public class MathExceptionTest extends TestCase { public void testPrintStackTrace() { String outMsg = "outer message"; String inMsg = "inner message"; - MathException cause = new MathConfigurationException(inMsg, new Object[0]); - MathException ex = new MathException(outMsg, new Object[0], cause); + MathException cause = new MathConfigurationException(inMsg, null); + MathException ex = new MathException(outMsg, null, cause); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); ex.printStackTrace(ps); @@ -104,8 +104,8 @@ public class MathExceptionTest extends TestCase { public void testSerialization() { String outMsg = "outer message"; String inMsg = "inner message"; - MathException cause = new MathConfigurationException(inMsg, new Object[0]); - MathException ex = new MathException(outMsg, new Object[0], cause); + MathException cause = new MathConfigurationException(inMsg, null); + MathException ex = new MathException(outMsg, null, cause); MathException image = (MathException) TestUtils.serializeAndRecover(ex); ByteArrayOutputStream baos = new ByteArrayOutputStream(); diff --git a/src/test/org/apache/commons/math/linear/InvalidMatrixExceptionTest.java b/src/test/org/apache/commons/math/linear/InvalidMatrixExceptionTest.java index 458ab454f..ab6516d3e 100644 --- a/src/test/org/apache/commons/math/linear/InvalidMatrixExceptionTest.java +++ b/src/test/org/apache/commons/math/linear/InvalidMatrixExceptionTest.java @@ -29,7 +29,7 @@ public class InvalidMatrixExceptionTest extends TestCase { */ public void testConstructorMessage(){ String msg = "message"; - InvalidMatrixException ex = new InvalidMatrixException(msg, new Object[0]); + InvalidMatrixException ex = new InvalidMatrixException(msg, null); assertEquals(msg, ex.getMessage()); } } diff --git a/src/test/org/apache/commons/math/linear/MatrixIndexExceptionTest.java b/src/test/org/apache/commons/math/linear/MatrixIndexExceptionTest.java index 210b245f4..57211032f 100644 --- a/src/test/org/apache/commons/math/linear/MatrixIndexExceptionTest.java +++ b/src/test/org/apache/commons/math/linear/MatrixIndexExceptionTest.java @@ -29,7 +29,7 @@ public class MatrixIndexExceptionTest extends TestCase { */ public void testConstructorMessage(){ String msg = "message"; - MatrixIndexException ex = new MatrixIndexException(msg, new Object[0]); + MatrixIndexException ex = new MatrixIndexException(msg, null); assertEquals(msg, ex.getMessage()); } } diff --git a/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java b/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java index 58d6427a0..7c226ae88 100644 --- a/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java +++ b/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java @@ -659,7 +659,7 @@ public final class RealMatrixImplTest extends TestCase { if (!lu.isSquare() || lowerData.length != lowerData[0].length || upperData.length != upperData[0].length || lowerData.length != upperData.length || lowerData.length != lu.getRowDimension()) { - throw new InvalidMatrixException("incorrect dimensions", new Object[0]); + throw new InvalidMatrixException("incorrect dimensions", null); } int n = lu.getRowDimension(); for (int i = 0; i < n; i++) {