diff --git a/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java b/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java index f384da34e..2280e5953 100644 --- a/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java +++ b/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java @@ -20,6 +20,7 @@ import org.apache.commons.math.ConvergingAlgorithmImpl; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; /** * Provide a default implementation for several generic functions. @@ -67,7 +68,7 @@ public abstract class UnivariateRealIntegratorImpl throws IllegalArgumentException { super(defaultMaximalIterationCount, 1.0e-15); if (f == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FUNCTION); + throw new NullArgumentException(LocalizedFormats.FUNCTION); } this.f = f; diff --git a/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java b/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java index 5f12cb6ab..59d62b7d0 100644 --- a/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java +++ b/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java @@ -22,6 +22,7 @@ import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; /** * Provide a default implementation for several functions useful to generic @@ -74,7 +75,7 @@ public abstract class UnivariateRealSolverImpl final double defaultAbsoluteAccuracy) { super(defaultMaximalIterationCount, defaultAbsoluteAccuracy); if (f == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FUNCTION); + throw new NullArgumentException(LocalizedFormats.FUNCTION); } this.f = f; this.defaultFunctionValueAccuracy = 1.0e-15; diff --git a/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java b/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java index b66a40b92..1ee435ae1 100644 --- a/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java +++ b/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java @@ -21,6 +21,7 @@ import org.apache.commons.math.ConvergenceException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; /** * Utility routines for {@link UnivariateRealSolver} objects. @@ -170,7 +171,7 @@ public class UnivariateRealSolverUtils { FunctionEvaluationException { if (function == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FUNCTION); + throw new NullArgumentException(LocalizedFormats.FUNCTION); } if (maximumIterations <= 0) { throw MathRuntimeException.createIllegalArgumentException( @@ -225,7 +226,7 @@ public class UnivariateRealSolverUtils { */ private static void setup(UnivariateRealFunction f) { if (f == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FUNCTION); + throw new NullArgumentException(LocalizedFormats.FUNCTION); } } diff --git a/src/main/java/org/apache/commons/math/complex/ComplexFormat.java b/src/main/java/org/apache/commons/math/complex/ComplexFormat.java index b57062503..871189615 100644 --- a/src/main/java/org/apache/commons/math/complex/ComplexFormat.java +++ b/src/main/java/org/apache/commons/math/complex/ComplexFormat.java @@ -26,6 +26,7 @@ import java.util.Locale; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; import org.apache.commons.math.util.CompositeFormat; +import org.apache.commons.math.exception.NullArgumentException; /** * Formats a Complex number in cartesian format "Re(c) + Im(c)i". 'i' can @@ -358,13 +359,11 @@ public class ComplexFormat extends CompositeFormat { /** * Modify the imaginaryFormat. * @param imaginaryFormat The new imaginaryFormat value. - * @throws IllegalArgumentException if imaginaryFormat is - * null. + * @throws NullArgumentException if {@code imaginaryFormat} is {@code null}. */ public void setImaginaryFormat(NumberFormat imaginaryFormat) { if (imaginaryFormat == null) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NULL_IMAGINARY_FORMAT); + throw new NullArgumentException(LocalizedFormats.IMAGINARY_FORMAT); } this.imaginaryFormat = imaginaryFormat; } @@ -372,13 +371,11 @@ public class ComplexFormat extends CompositeFormat { /** * Modify the realFormat. * @param realFormat The new realFormat value. - * @throws IllegalArgumentException if realFormat is - * null. + * @throws NullArgumentException if {@code realFormat} is {@code null}. */ public void setRealFormat(NumberFormat realFormat) { if (realFormat == null) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NULL_REAL_FORMAT); + throw new NullArgumentException(LocalizedFormats.REAL_FORMAT); } this.realFormat = realFormat; } diff --git a/src/main/java/org/apache/commons/math/exception/LocalizedFormats.java b/src/main/java/org/apache/commons/math/exception/LocalizedFormats.java index c14db2dd8..03fc6f896 100644 --- a/src/main/java/org/apache/commons/math/exception/LocalizedFormats.java +++ b/src/main/java/org/apache/commons/math/exception/LocalizedFormats.java @@ -145,11 +145,10 @@ public enum LocalizedFormats implements Localizable { NEGATIVE_COMPLEX_MODULE("negative complex module {0}"), NEGATIVE_ELEMENT_AT_2D_INDEX("element ({0}, {1}) is negative: {2}"), NEGATIVE_ELEMENT_AT_INDEX("element {0} is negative: {1}"), - NEGATIVE_LENGTH("length cannot be negative ({0})"), NEGATIVE_NUMBER_OF_SUCCESSES("number of successes must be non-negative ({0})"), NEGATIVE_NUMBER_OF_TRIALS("number of trials must be non-negative ({0})"), NEGATIVE_ROBUSTNESS_ITERATIONS("the number of robustness iterations must be non-negative, but got {0}"), - NEGATIVE_START_POSITION("start position cannot be negative ({0})"), + START_POSITION("start position ({0})"), /* keep */ NON_CONVERGENT_CONTINUED_FRACTION("Continued fraction convergents failed to converge for value {0}"), NON_POSITIVE_MICROSPHERE_ELEMENTS("number of microsphere elements must be positive, but got {0}"), NON_POSITIVE_POLYNOMIAL_DEGREE("polynomial degree must be positive: degree={0}"), @@ -211,18 +210,19 @@ public enum LocalizedFormats implements Localizable { NO_OPTIMUM_COMPUTED_YET("no optimum computed yet"), NO_RESULT_AVAILABLE("no result available"), NO_SUCH_MATRIX_ENTRY("no entry at indices ({0}, {1}) in a {2}x{3} matrix"), - NULL_COVARIANCE_MATRIX("covariance matrix is null"), - NULL_DENOMINATOR("denominator is null"), - NULL_DENOMINATOR_FORMAT("denominator format can not be null"), - NULL_FRACTION("null fraction"), - NULL_FUNCTION("function is null"), - NULL_IMAGINARY_FORMAT("null imaginary format"), - NULL_INPUT_ARRAY("input array is null"), - NULL_NUMERATOR("numerator is null"), - NULL_NUMERATOR_FORMAT("numerator format can not be null"), - NULL_OBJECT_TRANSFORMATION("Conversion Exception in Transformation, Object is null"), - NULL_REAL_FORMAT("null real format"), - NULL_WHOLE_FORMAT("whole format can not be null"), + NULL_NOT_ALLOWED("null is not allowed"), /* keep */ + COVARIANCE_MATRIX("covariance matrix"), /* keep */ + DENOMINATOR("denominator"), /* keep */ + DENOMINATOR_FORMAT("denominator format"), /* keep */ + FRACTION("fraction"), /* keep */ + FUNCTION("function"), /* keep */ + IMAGINARY_FORMAT("imaginary format"), /* keep */ + INPUT_ARRAY("input array"), /* keep */ + NUMERATOR("numerator"), /* keep */ + NUMERATOR_FORMAT("numerator format"), /* keep */ + OBJECT_TRANSFORMATION("conversion exception in transformation"), /* keep */ + REAL_FORMAT("real format"), /* keep */ + WHOLE_FORMAT("whole format"), /* keep */ NUMBER_TOO_LARGE("{0} is larger than the maximum ({1})"), /* keep */ NUMBER_TOO_SMALL("{0} is smaller than the minimum ({1})"), /* keep */ NUMBER_TOO_LARGE_BOUND_EXCLUDED("{0} is larger than, or equal to, the maximum ({1})"), /* keep */ diff --git a/src/main/java/org/apache/commons/math/exception/NullArgumentException.java b/src/main/java/org/apache/commons/math/exception/NullArgumentException.java new file mode 100644 index 000000000..80d6d9e1d --- /dev/null +++ b/src/main/java/org/apache/commons/math/exception/NullArgumentException.java @@ -0,0 +1,47 @@ +/* + * 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; + +/** + * All conditions checks that fail due to a {@code null} argument must throw + * this exception. + * This class is meant to signal a precondition violation ("null is an illegal + * argument") and so does not extend the standard {@code NullPointerException}. + * Proagation of {@code NullPointerException} from within Commons-Math is + * construed to be a bug. + * + * @since 2.2 + * @version $Revision$ $Date$ + */ +public class NullArgumentException extends MathIllegalArgumentException { + /** Serializable version Id. */ + private static final long serialVersionUID = -6024911025449780478L; + + /** + * Default constructor. + */ + public NullArgumentException() { + super(LocalizedFormats.NULL_NOT_ALLOWED); + } + /** + * @param specific Message pattern providing the specific context of + * the error. + */ + public NullArgumentException(Localizable specific) { + super(specific, LocalizedFormats.NULL_NOT_ALLOWED); + } +} diff --git a/src/main/java/org/apache/commons/math/exception/ZeroNotAllowedException.java b/src/main/java/org/apache/commons/math/exception/ZeroException.java similarity index 88% rename from src/main/java/org/apache/commons/math/exception/ZeroNotAllowedException.java rename to src/main/java/org/apache/commons/math/exception/ZeroException.java index d0a24db8d..d1dc01385 100644 --- a/src/main/java/org/apache/commons/math/exception/ZeroNotAllowedException.java +++ b/src/main/java/org/apache/commons/math/exception/ZeroException.java @@ -23,7 +23,7 @@ package org.apache.commons.math.exception; * @since 2.2 * @version $Revision$ $Date$ */ -public class ZeroNotAllowedException extends MathIllegalNumberException { +public class ZeroException extends MathIllegalNumberException { /** Serializable version identifier */ private static final long serialVersionUID = -1960874856936000015L; @@ -31,7 +31,7 @@ public class ZeroNotAllowedException extends MathIllegalNumberException { /** * Construct the exception. */ - public ZeroNotAllowedException() { + public ZeroException() { this(null); } @@ -40,8 +40,7 @@ public class ZeroNotAllowedException extends MathIllegalNumberException { * * @param specific Specific contexte pattern . */ - public ZeroNotAllowedException(Localizable specific) { + public ZeroException(Localizable specific) { super(specific, LocalizedFormats.ZERO_NOT_ALLOWED, 0); } - } diff --git a/src/main/java/org/apache/commons/math/fraction/AbstractFormat.java b/src/main/java/org/apache/commons/math/fraction/AbstractFormat.java index 29dc0afd1..5390c3bda 100644 --- a/src/main/java/org/apache/commons/math/fraction/AbstractFormat.java +++ b/src/main/java/org/apache/commons/math/fraction/AbstractFormat.java @@ -23,7 +23,7 @@ import java.text.NumberFormat; import java.text.ParsePosition; import java.util.Locale; -import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.LocalizedFormats; /** @@ -114,13 +114,11 @@ public abstract class AbstractFormat extends NumberFormat implements Serializabl /** * Modify the denominator format. * @param format the new denominator format value. - * @throws IllegalArgumentException if format is - * null. + * @throws NullArgumentException if {@code format} is {@code null}. */ public void setDenominatorFormat(final NumberFormat format) { if (format == null) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NULL_DENOMINATOR_FORMAT); + throw new NullArgumentException(LocalizedFormats.DENOMINATOR_FORMAT); } this.denominatorFormat = format; } @@ -128,13 +126,11 @@ public abstract class AbstractFormat extends NumberFormat implements Serializabl /** * Modify the numerator format. * @param format the new numerator format value. - * @throws IllegalArgumentException if format is - * null. + * @throws NullArgumentException if {@code format} is {@code null}. */ public void setNumeratorFormat(final NumberFormat format) { if (format == null) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NULL_NUMERATOR_FORMAT); + throw new NullArgumentException(LocalizedFormats.NUMERATOR_FORMAT); } this.numeratorFormat = format; } diff --git a/src/main/java/org/apache/commons/math/fraction/BigFraction.java b/src/main/java/org/apache/commons/math/fraction/BigFraction.java index 70fb64448..76042ac63 100644 --- a/src/main/java/org/apache/commons/math/fraction/BigFraction.java +++ b/src/main/java/org/apache/commons/math/fraction/BigFraction.java @@ -23,6 +23,7 @@ import java.math.BigInteger; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.util.MathUtils; /** @@ -104,19 +105,20 @@ public class BigFraction } /** - *

* Create a {@link BigFraction} given the numerator and denominator as - * BigInteger. The {@link BigFraction} is reduced to lowest terms. - *

+ * {@code BigInteger}. The {@link BigFraction} is reduced to lowest terms. * - * @param num - * the numerator, must not be null. - * @param den - * the denominator, must not be null. - * @throws ArithmeticException - * if the denominator is zero. + * @param num the numerator, must not be {@code null}. + * @param den the denominator, must not be {@code null}.. + * @throws ArithmeticException if the denominator is zero. */ public BigFraction(BigInteger num, BigInteger den) { + if (num == null) { + throw new NullArgumentException(LocalizedFormats.NUMERATOR); + } + if (den == null) { + throw new NullArgumentException(LocalizedFormats.DENOMINATOR); + } if (BigInteger.ZERO.equals(den)) { throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); } @@ -498,10 +500,12 @@ public class BigFraction * @param fraction * the {@link BigFraction} to add, must not be null. * @return a {@link BigFraction} instance with the resulting values. - * @throws NullPointerException - * if the {@link BigFraction} is null. + * @throws NullArgumentException if the {@link BigFraction} is {@code null}. */ public BigFraction add(final BigFraction fraction) { + if (fraction == null) { + throw new NullArgumentException(LocalizedFormats.FRACTION); + } if (ZERO.equals(fraction)) { return this; } @@ -601,8 +605,7 @@ public class BigFraction * the BigInteger to divide by, must not be * null. * @return a {@link BigFraction} instance with the resulting values. - * @throws NullPointerException - * if the BigInteger is null. + * @throws NullArgumentException if the {@code BigInteger} is {@code null}. * @throws ArithmeticException * if the fraction to divide by is zero. */ @@ -651,15 +654,15 @@ public class BigFraction * reduced form. *

* - * @param fraction - * the fraction to divide by, must not be null. + * @param fraction Fraction to divide by, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values. - * @throws NullPointerException - * if the fraction is null. - * @throws ArithmeticException - * if the fraction to divide by is zero. + * @throws NullArgumentException if the {@code fraction} is {@code null}. + * @throws ArithmeticException if the fraction to divide by is zero. */ public BigFraction divide(final BigFraction fraction) { + if (fraction == null) { + throw new NullArgumentException(LocalizedFormats.FRACTION); + } if (BigInteger.ZERO.equals(fraction.numerator)) { throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); } @@ -838,13 +841,14 @@ public class BigFraction * BigInteger, returning the result in reduced form. *

* - * @param bg - * the BigInteger to multiply by. - * @return a BigFraction instance with the resulting values. - * @throws NullPointerException - * if the bg is null. + * @param bg the {@code BigInteger} to multiply by. + * @return a {@code BigFraction} instance with the resulting values. + * @throws NullArgumentException if {@code bg} is {@code null}. */ public BigFraction multiply(final BigInteger bg) { + if (bg == null) { + throw new NullArgumentException(); + } return new BigFraction(bg.multiply(numerator), denominator); } @@ -882,13 +886,14 @@ public class BigFraction * reduced form. *

* - * @param fraction - * the fraction to multiply by, must not be null. + * @param fraction Fraction to multiply by, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values. - * @throws NullPointerException - * if the fraction is null. + * @throws NullArgumentException if {@code fraction} is {@code null}. */ public BigFraction multiply(final BigFraction fraction) { + if (fraction == null) { + throw new NullArgumentException(LocalizedFormats.FRACTION); + } if (numerator.equals(BigInteger.ZERO) || fraction.numerator.equals(BigInteger.ZERO)) { return ZERO; @@ -1023,14 +1028,14 @@ public class BigFraction * returning the result in reduced form. *

* - * @param bg - * the {@link BigInteger} to subtract, must'nt be - * null. - * @return a BigFraction instance with the resulting values. - * @throws NullPointerException - * if the {@link BigInteger} is null. + * @param bg the {@link BigInteger} to subtract, cannot be {@code null}. + * @return a {@code BigFraction} instance with the resulting values. + * @throws NullArgumentException if the {@link BigInteger} is {@code null}. */ public BigFraction subtract(final BigInteger bg) { + if (bg == null) { + throw new NullArgumentException(); + } return new BigFraction(numerator.subtract(denominator.multiply(bg)), denominator); } @@ -1069,14 +1074,14 @@ public class BigFraction * returning the result in reduced form. *

* - * @param fraction - * the {@link BigFraction} to subtract, must not be - * null. + * @param fraction {@link BigFraction} to subtract, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values - * @throws NullPointerException - * if the fraction is null. + * @throws NullArgumentException if the {@code fraction} is {@code null}. */ public BigFraction subtract(final BigFraction fraction) { + if (fraction == null) { + throw new NullArgumentException(LocalizedFormats.FRACTION); + } if (ZERO.equals(fraction)) { return this; } diff --git a/src/main/java/org/apache/commons/math/fraction/Fraction.java b/src/main/java/org/apache/commons/math/fraction/Fraction.java index 67f53e5a3..0052c27b1 100644 --- a/src/main/java/org/apache/commons/math/fraction/Fraction.java +++ b/src/main/java/org/apache/commons/math/fraction/Fraction.java @@ -22,6 +22,7 @@ import java.math.BigInteger; import org.apache.commons.math.FieldElement; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.util.MathUtils; /** @@ -473,7 +474,7 @@ public class Fraction */ private Fraction addSub(Fraction fraction, boolean isAdd) { if (fraction == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FRACTION); + throw new NullArgumentException(LocalizedFormats.FRACTION); } // zero is identity for addition. if (numerator == 0) { @@ -530,7 +531,7 @@ public class Fraction */ public Fraction multiply(Fraction fraction) { if (fraction == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FRACTION); + throw new NullArgumentException(LocalizedFormats.FRACTION); } if (numerator == 0 || fraction.numerator == 0) { return ZERO; @@ -565,7 +566,7 @@ public class Fraction */ public Fraction divide(Fraction fraction) { if (fraction == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_FRACTION); + throw new NullArgumentException(LocalizedFormats.FRACTION); } if (fraction.numerator == 0) { throw MathRuntimeException.createArithmeticException( diff --git a/src/main/java/org/apache/commons/math/fraction/ProperBigFractionFormat.java b/src/main/java/org/apache/commons/math/fraction/ProperBigFractionFormat.java index d5ad09176..bd12a5a22 100644 --- a/src/main/java/org/apache/commons/math/fraction/ProperBigFractionFormat.java +++ b/src/main/java/org/apache/commons/math/fraction/ProperBigFractionFormat.java @@ -21,8 +21,8 @@ import java.text.FieldPosition; import java.text.NumberFormat; import java.text.ParsePosition; -import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; /** * Formats a BigFraction number in proper format. The number format for each of @@ -228,15 +228,12 @@ public class ProperBigFractionFormat extends BigFractionFormat { /** * Modify the whole format. * @param format The new whole format value. - * @throws IllegalArgumentException if format is - * null. + * @throws NullArgumentException if {@code format} is {@code null}. */ public void setWholeFormat(final NumberFormat format) { if (format == null) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NULL_WHOLE_FORMAT); + throw new NullArgumentException(LocalizedFormats.WHOLE_FORMAT); } this.wholeFormat = format; } - } diff --git a/src/main/java/org/apache/commons/math/fraction/ProperFractionFormat.java b/src/main/java/org/apache/commons/math/fraction/ProperFractionFormat.java index c83436384..a8dd6df21 100644 --- a/src/main/java/org/apache/commons/math/fraction/ProperFractionFormat.java +++ b/src/main/java/org/apache/commons/math/fraction/ProperFractionFormat.java @@ -20,8 +20,8 @@ import java.text.FieldPosition; import java.text.NumberFormat; import java.text.ParsePosition; -import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.util.MathUtils; /** @@ -221,13 +221,11 @@ public class ProperFractionFormat extends FractionFormat { /** * Modify the whole format. * @param format The new whole format value. - * @throws IllegalArgumentException if format is - * null. + * @throws NullArgumentException if {@code format} is {@code null}. */ public void setWholeFormat(NumberFormat format) { if (format == null) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NULL_WHOLE_FORMAT); + throw new NullArgumentException(LocalizedFormats.WHOLE_FORMAT); } this.wholeFormat = format; } diff --git a/src/main/java/org/apache/commons/math/optimization/fitting/GaussianDerivativeFunction.java b/src/main/java/org/apache/commons/math/optimization/fitting/GaussianDerivativeFunction.java index 4a7580f46..10d040cd1 100644 --- a/src/main/java/org/apache/commons/math/optimization/fitting/GaussianDerivativeFunction.java +++ b/src/main/java/org/apache/commons/math/optimization/fitting/GaussianDerivativeFunction.java @@ -24,7 +24,8 @@ import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.LocalizedFormats; -import org.apache.commons.math.exception.ZeroNotAllowedException; +import org.apache.commons.math.exception.ZeroException; +import org.apache.commons.math.exception.NullArgumentException; /** * The derivative of {@link GaussianFunction}. Specifically: @@ -65,7 +66,7 @@ public class GaussianDerivativeFunction implements UnivariateRealFunction, Seria */ public GaussianDerivativeFunction(double b, double c, double d) { if (d == 0.0) { - throw new ZeroNotAllowedException(); + throw new ZeroException(); } this.b = b; this.c = c; @@ -83,13 +84,13 @@ public class GaussianDerivativeFunction implements UnivariateRealFunction, Seria */ public GaussianDerivativeFunction(double[] parameters) { if (parameters == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (parameters.length != 3) { throw new DimensionMismatchException(3, parameters.length); } if (parameters[2] == 0.0) { - throw new ZeroNotAllowedException(); + throw new ZeroException(); } this.b = parameters[0]; this.c = parameters[1]; diff --git a/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFitter.java b/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFitter.java index 732fa5c17..aa240539f 100644 --- a/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFitter.java +++ b/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFitter.java @@ -18,8 +18,7 @@ package org.apache.commons.math.optimization.fitting; import org.apache.commons.math.FunctionEvaluationException; -import org.apache.commons.math.optimization. - DifferentiableMultivariateVectorialOptimizer; +import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer; import org.apache.commons.math.optimization.OptimizationException; import org.apache.commons.math.optimization.fitting.CurveFitter; import org.apache.commons.math.optimization.fitting.WeightedObservedPoint; diff --git a/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFunction.java b/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFunction.java index 7a7144218..ab51a10ee 100644 --- a/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFunction.java +++ b/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFunction.java @@ -25,7 +25,8 @@ import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.LocalizedFormats; -import org.apache.commons.math.exception.ZeroNotAllowedException; +import org.apache.commons.math.exception.ZeroException; +import org.apache.commons.math.exception.NullArgumentException; /** * A Gaussian function. Specifically: @@ -77,7 +78,7 @@ public class GaussianFunction implements DifferentiableUnivariateRealFunction, S */ public GaussianFunction(double a, double b, double c, double d) { if (d == 0.0) { - throw new ZeroNotAllowedException(); + throw new ZeroException(); } this.a = a; this.b = b; @@ -97,13 +98,13 @@ public class GaussianFunction implements DifferentiableUnivariateRealFunction, S */ public GaussianFunction(double[] parameters) { if (parameters == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (parameters.length != 4) { throw new DimensionMismatchException(4, parameters.length); } if (parameters[3] == 0.0) { - throw new ZeroNotAllowedException(); + throw new ZeroException(); } this.a = parameters[0]; this.b = parameters[1]; diff --git a/src/main/java/org/apache/commons/math/optimization/fitting/GaussianParametersGuesser.java b/src/main/java/org/apache/commons/math/optimization/fitting/GaussianParametersGuesser.java index 5d6f58947..7f983436a 100644 --- a/src/main/java/org/apache/commons/math/optimization/fitting/GaussianParametersGuesser.java +++ b/src/main/java/org/apache/commons/math/optimization/fitting/GaussianParametersGuesser.java @@ -20,14 +20,14 @@ package org.apache.commons.math.optimization.fitting; import java.util.Arrays; import java.util.Comparator; -import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; import org.apache.commons.math.exception.NumberIsTooSmallException; import org.apache.commons.math.exception.OutOfRangeException; -import org.apache.commons.math.exception.ZeroNotAllowedException; +import org.apache.commons.math.exception.ZeroException; +import org.apache.commons.math.exception.NullArgumentException; /** - * Guesses the parameters (a, b, c, and d) + * Guesses the parameters ({@code a}, {@code b}, {@code c}, and {@code d}) * of a {@link ParametricGaussianFunction} based on the specified observed * points. * @@ -49,7 +49,7 @@ public class GaussianParametersGuesser { */ public GaussianParametersGuesser(WeightedObservedPoint[] observations) { if (observations == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (observations.length < 3) { throw new NumberIsTooSmallException(observations.length, 3, true); @@ -154,7 +154,7 @@ public class GaussianParametersGuesser { private double interpolateXAtY(WeightedObservedPoint[] points, int startIdx, int idxStep, double y) throws OutOfRangeException { if (idxStep == 0) { - throw new ZeroNotAllowedException(); + throw new ZeroException(); } WeightedObservedPoint[] twoPoints = getInterpolationPointsForY(points, startIdx, idxStep, y); WeightedObservedPoint pointA = twoPoints[0]; @@ -190,7 +190,7 @@ public class GaussianParametersGuesser { int startIdx, int idxStep, double y) throws OutOfRangeException { if (idxStep == 0) { - throw new ZeroNotAllowedException(); + throw new ZeroException(); } for (int i = startIdx; (idxStep < 0) ? (i + idxStep >= 0) : (i + idxStep < points.length); diff --git a/src/main/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunction.java b/src/main/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunction.java index 936d9e0d1..3a28ce57a 100644 --- a/src/main/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunction.java +++ b/src/main/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunction.java @@ -20,10 +20,10 @@ package org.apache.commons.math.optimization.fitting; import java.io.Serializable; import org.apache.commons.math.FunctionEvaluationException; -import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.LocalizedFormats; -import org.apache.commons.math.exception.ZeroNotAllowedException; +import org.apache.commons.math.exception.ZeroException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.optimization.fitting.ParametricRealFunction; /** @@ -153,13 +153,13 @@ public class ParametricGaussianFunction implements ParametricRealFunction, Seria */ private void validateParameters(double[] parameters) throws FunctionEvaluationException { if (parameters == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (parameters.length != 4) { throw new DimensionMismatchException(4, parameters.length); } if (parameters[3] == 0.0) { - throw new ZeroNotAllowedException(); + throw new ZeroException(); } } diff --git a/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java b/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java index 0a2859f63..0ac847df9 100644 --- a/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java +++ b/src/main/java/org/apache/commons/math/stat/correlation/PearsonsCorrelation.java @@ -21,6 +21,8 @@ import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.distribution.TDistribution; import org.apache.commons.math.distribution.TDistributionImpl; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; +import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.linear.RealMatrix; import org.apache.commons.math.linear.BlockRealMatrix; import org.apache.commons.math.stat.regression.SimpleRegression; @@ -92,7 +94,7 @@ public class PearsonsCorrelation { public PearsonsCorrelation(Covariance covariance) { RealMatrix covarianceMatrix = covariance.getCovarianceMatrix(); if (covarianceMatrix == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_COVARIANCE_MATRIX); + throw new NullArgumentException(LocalizedFormats.COVARIANCE_MATRIX); } nObs = covariance.getN(); correlationMatrix = covarianceToCorrelation(covarianceMatrix); @@ -225,8 +227,7 @@ public class PearsonsCorrelation { public double correlation(final double[] xArray, final double[] yArray) throws IllegalArgumentException { SimpleRegression regression = new SimpleRegression(); if (xArray.length != yArray.length) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, xArray.length, yArray.length); + throw new DimensionMismatchException(xArray.length, yArray.length); } else if (xArray.length < 2) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.INSUFFICIENT_DIMENSION, xArray.length, 2); diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java b/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java index bb6eaf991..7dbf30758 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java @@ -16,8 +16,8 @@ */ package org.apache.commons.math.stat.descriptive; -import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.util.MathUtils; /** @@ -56,7 +56,7 @@ public abstract class AbstractStorelessUnivariateStatistic @Override public double evaluate(final double[] values) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } return evaluate(values, 0, values.length); } @@ -124,7 +124,7 @@ public abstract class AbstractStorelessUnivariateStatistic */ public void incrementAll(double[] values) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } incrementAll(values, 0, values.length); } diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java b/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java index 29d0992c9..18c50ef48 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java @@ -18,6 +18,9 @@ package org.apache.commons.math.stat.descriptive; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; +import org.apache.commons.math.exception.NotPositiveException; +import org.apache.commons.math.exception.DimensionMismatchException; /** * Abstract base class for all implementations of the @@ -78,17 +81,15 @@ public abstract class AbstractUnivariateStatistic final int length) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (begin < 0) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NEGATIVE_START_POSITION, begin); + throw new NotPositiveException(LocalizedFormats.START_POSITION, begin); } if (length < 0) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.NEGATIVE_LENGTH, length); + throw new NotPositiveException(LocalizedFormats.LENGTH, length); } if (begin + length > values.length) { @@ -140,12 +141,11 @@ public abstract class AbstractUnivariateStatistic final int length) { if (weights == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } - if (weights.length != values.length) { - throw MathRuntimeException.createIllegalArgumentException( - LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, weights.length, values.length); + if (weights.length != values.length) { + throw new DimensionMismatchException(weights.length, values.length); } boolean containsPositiveWeight = false; diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java index 6df2b45e4..652b90179 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/SemiVariance.java @@ -18,7 +18,7 @@ package org.apache.commons.math.stat.descriptive.moment; import java.io.Serializable; -import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.LocalizedFormats; import org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic; @@ -176,7 +176,7 @@ public class SemiVariance extends AbstractUnivariateStatistic implements Seriali @Override public double evaluate(final double[] values) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } return evaluate(values, 0, values.length); } diff --git a/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java b/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java index 375cc1f19..1bb3f7544 100644 --- a/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java +++ b/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java @@ -18,7 +18,7 @@ package org.apache.commons.math.stat.descriptive.moment; import java.io.Serializable; -import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.LocalizedFormats; import org.apache.commons.math.stat.descriptive.WeightedEvaluation; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; @@ -214,7 +214,7 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se @Override public double evaluate(final double[] values) { if (values == null) { - throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.NULL_INPUT_ARRAY); + throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } return evaluate(values, 0, values.length); } @@ -589,7 +589,6 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se return result; } - /** * Copies source to dest. *

Neither source nor dest can be null.

@@ -599,9 +598,12 @@ public class Variance extends AbstractStorelessUnivariateStatistic implements Se * @throws NullPointerException if either source or dest is null */ public static void copy(Variance source, Variance dest) { + if (source == null || + dest == null) { + throw new NullArgumentException(); + } dest.moment = source.moment.copy(); dest.isBiasCorrected = source.isBiasCorrected; dest.incMoment = source.incMoment; } - } diff --git a/src/main/java/org/apache/commons/math/util/DefaultTransformer.java b/src/main/java/org/apache/commons/math/util/DefaultTransformer.java index c51209e4f..a17a79e7c 100644 --- a/src/main/java/org/apache/commons/math/util/DefaultTransformer.java +++ b/src/main/java/org/apache/commons/math/util/DefaultTransformer.java @@ -21,6 +21,7 @@ import java.io.Serializable; import org.apache.commons.math.MathException; import org.apache.commons.math.exception.LocalizedFormats; +import org.apache.commons.math.exception.NullArgumentException; /** * A Default NumberTransformer for java.lang.Numbers and Numeric Strings. This @@ -38,14 +39,13 @@ public class DefaultTransformer implements NumberTransformer, Serializable { /** * @param o the object that gets transformed. * @return a double primitive representation of the Object o. - * @throws org.apache.commons.math.MathException If it cannot successfully - * be transformed or is null. + * @throws MathException if it cannot successfully be transformed. + * @throws NullArgumentException if is {@code null}. * @see */ - public double transform(Object o) throws MathException{ - + public double transform(Object o) throws MathException { if (o == null) { - throw new MathException(LocalizedFormats.NULL_OBJECT_TRANSFORMATION); + throw new NullArgumentException(LocalizedFormats.OBJECT_TRANSFORMATION); } if (o instanceof Number) { diff --git a/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties b/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties index 18afba968..0f8b345a0 100644 --- a/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties +++ b/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties @@ -117,11 +117,10 @@ NEGATIVE_BRIGHTNESS_EXPONENT = l''exposant de brillance devrait \u00eatre positi NEGATIVE_COMPLEX_MODULE = module n\u00e9gatif ({0}) pour un nombre complexe NEGATIVE_ELEMENT_AT_2D_INDEX = l''\u00e9l\u00e9ment ({0}, {1}) est n\u00e9gatif : {2} NEGATIVE_ELEMENT_AT_INDEX = l''\u00e9l\u00e9ment {0} est n\u00e9gatif : {1} -NEGATIVE_LENGTH = la longueur ne peut pas \u00eatre n\u00e9gative NEGATIVE_NUMBER_OF_SUCCESSES = le nombre de succ\u00e8s ne doit pas \u00eatre n\u00e9gatif ({0}) NEGATIVE_NUMBER_OF_TRIALS = le nombre d''essais ne doit pas \u00eatre n\u00e9gatif ({0}) NEGATIVE_ROBUSTNESS_ITERATIONS = le nombre d''it\u00e9rations robuste ne peut \u00eatre n\u00e9gatif, alors qu''il est de {0} -NEGATIVE_START_POSITION = la position de d\u00e9part ne peut pas \u00eatre n\u00e9gative +START_POSITION = position de d\u00e9part NON_CONVERGENT_CONTINUED_FRACTION = \u00c9chec de convergence de fraction continue pour la valeur {0} NON_POSITIVE_MICROSPHERE_ELEMENTS = le nombre d''\u00e9l\u00e9ments de la microsph\u00e8re devrait \u00eatre positif, or n = {0} NON_POSITIVE_POLYNOMIAL_DEGREE = le polyn\u00f4me doit \u00eatre de degr\u00e9 positif : degr\u00e9 = {0} @@ -189,12 +188,12 @@ DENOMINATOR = d\u00e9nominateur DENOMINATOR_FORMAT = format du d\u00e9nominateur FRACTION = fraction FUNCTION = fonction -IMAGINARY_FORMAT = format imaginaire +IMAGINARY_FORMAT = format de la partie imaginaire INPUT_ARRAY = tableau d''entr\u00e9e NUMERATOR = num\u00e9rateur NUMERATOR_FORMAT = format du num\u00e9rateur OBJECT_TRANSFORMATION = exception de conversion dans une transformation -REAL_FORMAT = format r\u00e9el +REAL_FORMAT = format de la partie r\u00e9elle WHOLE_FORMAT = format complet NUMBER_TOO_LARGE = {0} est plus grand que le maximum ({1}) NUMBER_TOO_SMALL = {0} est plus petit que le minimum ({1}) diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index 7d8200b9a..37a6616a7 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -96,6 +96,8 @@ The type attribute can be add,update,fix,remove. Created package "exception" to contain the new exceptions hierarchy. Created package "exception.util": utilities for the exception classes (e.g. managing the localization of error messages). + Default policy for dealing with invalid null references: raise a + "NullArgumentException" (subclass of "IllegalArgumentException"). Implementation of linear interpolation. diff --git a/src/site/xdoc/userguide/overview.xml b/src/site/xdoc/userguide/overview.xml index 0842b02d5..47fd6de0d 100644 --- a/src/site/xdoc/userguide/overview.xml +++ b/src/site/xdoc/userguide/overview.xml @@ -93,7 +93,7 @@ -

+

You should always read the javadoc class and method comments carefully when using Commons Math components in your programs. The javadoc provides references to the algorithms that are used, usage notes about limitations, performance, etc. as well as interface contracts. @@ -101,16 +101,27 @@ for the method to return valid results), special values returned (e.g. Double.NaN) or exceptions that may be thrown if the preconditions are not met, and definitions for returned values/objects or state changes.

-

- When the actual parameters provided to a method or the internal state of an object - make a computation meaningless, an IllegalArgumentException or IllegalStateException may - be thrown. Exact conditions under which runtime exceptions (and any other exceptions) are - thrown are specified in the javadoc method comments. In some cases, to be consistent with - the IEEE 754 standard for floating point - arithmetic and with java.lang.Math, Commons Math methods return Double.NaN values. - Conditions under which Double.NaN or other special values are returned are fully specified - in the javadoc method comments. -

+

+ When the actual parameters provided to a method or the internal state of an object + make a computation meaningless, an IllegalArgumentException or IllegalStateException may + be thrown. Exact conditions under which runtime exceptions (and any other exceptions) are + thrown are specified in the javadoc method comments. In some cases, to be consistent with + the IEEE 754 standard for floating point + arithmetic and with java.lang.Math, Commons Math methods return Double.NaN values. + Conditions under which Double.NaN or other special values are returned are fully specified + in the javadoc method comments. +

+

+ As of version 2.2, the policy for dealing with null references is as + follows: When an argument is unexpectedly null, a + + NullArgumentException is raised for signalling the + illegal argument. Note that this class does not inherit from the + standard NullPointerException but is a subclass of + IllegalArgumentException. + No NullPointerException should be propagated from within + Commons-Math. +

diff --git a/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java b/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java index 4216f735c..656d985b2 100644 --- a/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java +++ b/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java @@ -21,6 +21,7 @@ import java.math.BigInteger; import org.apache.commons.math.ConvergenceException; import org.apache.commons.math.TestUtils; +import org.apache.commons.math.exception.NullArgumentException; import junit.framework.TestCase; @@ -64,12 +65,12 @@ public class BigFractionTest extends TestCase { assertFraction(1055531162664967l, 70368744177664l, new BigFraction(15.0000000000001)); try { new BigFraction(null, BigInteger.ONE); - } catch (NullPointerException npe) { + } catch (NullArgumentException npe) { // expected } try { new BigFraction(BigInteger.ONE, null); - } catch (NullPointerException npe) { + } catch (NullArgumentException npe) { // expected } try { @@ -326,8 +327,8 @@ public class BigFractionTest extends TestCase { try { f.add((BigFraction) null); - fail("expecting NullPointerException"); - } catch (NullPointerException ex) { + fail("expecting NullArgumentException"); + } catch (NullArgumentException ex) { } // if this fraction is added naively, it will overflow. @@ -414,8 +415,8 @@ public class BigFractionTest extends TestCase { try { f.divide((BigFraction) null); - fail("expecting NullPointerException"); - } catch (NullPointerException ex) { + fail("expecting NullArgumentException"); + } catch (NullArgumentException ex) { } f1 = new BigFraction(Integer.MIN_VALUE, Integer.MAX_VALUE); @@ -460,8 +461,8 @@ public class BigFractionTest extends TestCase { try { f.multiply((BigFraction) null); - fail("expecting NullPointerException"); - } catch (NullPointerException ex) { + fail("expecting NullArgumentException"); + } catch (NullArgumentException ex) { } } @@ -478,8 +479,8 @@ public class BigFractionTest extends TestCase { BigFraction f = new BigFraction(1, 1); try { f.subtract((BigFraction) null); - fail("expecting NullPointerException"); - } catch (NullPointerException ex) { + fail("expecting NullArgumentException"); + } catch (NullArgumentException ex) { } // if this fraction is subtracted naively, it will overflow. diff --git a/src/test/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunctionTest.java b/src/test/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunctionTest.java index 134521e17..bf96cd993 100644 --- a/src/test/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunctionTest.java +++ b/src/test/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunctionTest.java @@ -18,7 +18,7 @@ package org.apache.commons.math.optimization.fitting; import org.apache.commons.math.FunctionEvaluationException; -import org.apache.commons.math.exception.ZeroNotAllowedException; +import org.apache.commons.math.exception.ZeroException; import org.apache.commons.math.optimization.OptimizationException; import org.apache.commons.math.optimization.fitting.CurveFitter; import org.apache.commons.math.optimization.general. @@ -133,7 +133,7 @@ public class ParametricGaussianFunctionTest { * * @throws FunctionEvaluationException in the event of a test case error */ - @Test(expected=ZeroNotAllowedException.class) + @Test(expected=ZeroException.class) public void testValue03() throws FunctionEvaluationException { ParametricGaussianFunction f = new ParametricGaussianFunction(); f.value(0.0, new double[] {0.0, 1.0, 1.0, 0.0}); diff --git a/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java b/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java index daa5b9b29..627a221d9 100644 --- a/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java +++ b/src/test/java/org/apache/commons/math/util/DefaultTransformerTest.java @@ -23,6 +23,7 @@ import junit.framework.TestCase; import org.apache.commons.math.MathException; import org.apache.commons.math.TestUtils; +import org.apache.commons.math.exception.NullArgumentException; /** * @version $Revision$ $Date$ @@ -41,12 +42,12 @@ public class DefaultTransformerTest extends TestCase { /** * */ - public void testTransformNull(){ + public void testTransformNull() throws Exception { DefaultTransformer t = new DefaultTransformer(); try { t.transform(null); - fail("Expection MathException"); - } catch (MathException e) { + fail("Expecting NullArgumentException"); + } catch (NullArgumentException e) { // expected } }