From aa3b4bbccc1a61758b848543122c8e4f258786cc Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 31 Jul 2003 23:45:28 +0000 Subject: [PATCH] Unify exception handling re IAE git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137544 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/lang/ArrayUtils.java | 4 +- .../commons/lang/SerializationUtils.java | 8 ++-- .../commons/lang/StringEscapeUtils.java | 6 +-- .../lang/exception/ExceptionUtils.java | 9 ++-- .../apache/commons/lang/math/NumberUtils.java | 43 +++++++++---------- 5 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/java/org/apache/commons/lang/ArrayUtils.java b/src/java/org/apache/commons/lang/ArrayUtils.java index da3598070..724c6c627 100644 --- a/src/java/org/apache/commons/lang/ArrayUtils.java +++ b/src/java/org/apache/commons/lang/ArrayUtils.java @@ -75,7 +75,7 @@ * @author Nikolay Metchev * @author Matthew Hawthorne * @since 2.0 - * @version $Id: ArrayUtils.java,v 1.19 2003/07/19 20:17:12 scolebourne Exp $ + * @version $Id: ArrayUtils.java,v 1.20 2003/07/31 23:45:28 scolebourne Exp $ */ public class ArrayUtils { @@ -607,7 +607,7 @@ public static boolean isSameLength(final boolean[] array1, final boolean[] array */ public static boolean isSameType(final Object array1, final Object array2) { if (array1 == null || array2 == null) { - throw new NullArgumentException("Array"); + throw new IllegalArgumentException("The Array must not be null"); } return array1.getClass().getName().equals(array2.getClass().getName()); } diff --git a/src/java/org/apache/commons/lang/SerializationUtils.java b/src/java/org/apache/commons/lang/SerializationUtils.java index 7bf5d680d..925bd68fb 100644 --- a/src/java/org/apache/commons/lang/SerializationUtils.java +++ b/src/java/org/apache/commons/lang/SerializationUtils.java @@ -81,7 +81,7 @@ * @author Stephen Colebourne * @author Jeff Varszegi * @since 1.0 - * @version $Id: SerializationUtils.java,v 1.7 2003/07/19 20:22:36 scolebourne Exp $ + * @version $Id: SerializationUtils.java,v 1.8 2003/07/31 23:45:28 scolebourne Exp $ */ public class SerializationUtils { @@ -130,7 +130,7 @@ public static Object clone(Serializable object) { */ public static void serialize(Serializable obj, OutputStream outputStream) { if (outputStream == null) { - throw new NullArgumentException("OutputStream"); + throw new IllegalArgumentException("The OutputStream must not be null"); } ObjectOutputStream out = null; try { @@ -182,7 +182,7 @@ public static byte[] serialize(Serializable obj) { */ public static Object deserialize(InputStream inputStream) { if (inputStream == null) { - throw new NullArgumentException("InputStream"); + throw new IllegalArgumentException("The InputStream must not be null"); } ObjectInputStream in = null; try { @@ -215,7 +215,7 @@ public static Object deserialize(InputStream inputStream) { */ public static Object deserialize(byte[] objectData) { if (objectData == null) { - throw new NullArgumentException("byte[]"); + throw new IllegalArgumentException("The byte[] must not be null"); } ByteArrayInputStream bais = new ByteArrayInputStream(objectData); return deserialize(bais); diff --git a/src/java/org/apache/commons/lang/StringEscapeUtils.java b/src/java/org/apache/commons/lang/StringEscapeUtils.java index 327398e36..88e78cc5c 100644 --- a/src/java/org/apache/commons/lang/StringEscapeUtils.java +++ b/src/java/org/apache/commons/lang/StringEscapeUtils.java @@ -73,7 +73,7 @@ * @author Gary Gregory * @author Phil Steitz * @since 2.0 - * @version $Id: StringEscapeUtils.java,v 1.21 2003/07/28 16:17:57 ggregory Exp $ + * @version $Id: StringEscapeUtils.java,v 1.22 2003/07/31 23:45:28 scolebourne Exp $ */ public class StringEscapeUtils { @@ -191,7 +191,7 @@ private static String escapeJavaStyleString(String str, boolean escapeSingleQuot private static void escapeJavaStyleString(Writer out, String str, boolean escapeSingleQuote) throws IOException { if (out == null) { - throw new NullArgumentException("Writer"); + throw new IllegalArgumentException("The Writer must not be null"); } if (str == null) { return; @@ -311,7 +311,7 @@ public static String unescapeJava(String str) { */ public static void unescapeJava(Writer out, String str) throws IOException { if (out == null) { - throw new NullArgumentException("Writer"); + throw new IllegalArgumentException("The Writer must not be null"); } if (str == null) { return; diff --git a/src/java/org/apache/commons/lang/exception/ExceptionUtils.java b/src/java/org/apache/commons/lang/exception/ExceptionUtils.java index 7a6b2fd9f..b53335ed0 100644 --- a/src/java/org/apache/commons/lang/exception/ExceptionUtils.java +++ b/src/java/org/apache/commons/lang/exception/ExceptionUtils.java @@ -67,7 +67,6 @@ import java.util.StringTokenizer; import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.NullArgumentException; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.SystemUtils; @@ -80,7 +79,7 @@ * @author Stephen Colebourne * @author Gary Gregory * @since 1.0 - * @version $Id: ExceptionUtils.java,v 1.30 2003/07/26 14:22:21 scolebourne Exp $ + * @version $Id: ExceptionUtils.java,v 1.31 2003/07/31 23:45:28 scolebourne Exp $ */ public class ExceptionUtils { @@ -509,7 +508,7 @@ public static void printRootCauseStackTrace(Throwable throwable, PrintStream str return; } if (stream == null) { - throw new NullArgumentException("PrintStream"); + throw new IllegalArgumentException("The PrintStream must not be null"); } String trace[] = getRootCauseStackTrace(throwable); for (int i = 0; i < trace.length; i++) { @@ -538,7 +537,7 @@ public static void printRootCauseStackTrace(Throwable throwable, PrintWriter wri return; } if (writer == null) { - throw new NullArgumentException("PrintWriter"); + throw new IllegalArgumentException("The PrintWriter must not be null"); } String trace[] = getRootCauseStackTrace(throwable); for (int i = 0; i < trace.length; i++) { @@ -590,7 +589,7 @@ public static String[] getRootCauseStackTrace(Throwable throwable) { */ public static void removeCommonFrames(List causeFrames, List wrapperFrames) { if (causeFrames == null || wrapperFrames == null) { - throw new NullArgumentException("List"); + throw new IllegalArgumentException("The List must not be null"); } int causeFrameIndex = causeFrames.size() - 1; int wrapperFrameIndex = wrapperFrames.size() - 1; diff --git a/src/java/org/apache/commons/lang/math/NumberUtils.java b/src/java/org/apache/commons/lang/math/NumberUtils.java index f6e54c4ab..927cbf1a4 100644 --- a/src/java/org/apache/commons/lang/math/NumberUtils.java +++ b/src/java/org/apache/commons/lang/math/NumberUtils.java @@ -56,7 +56,6 @@ import java.math.BigDecimal; import java.math.BigInteger; -import org.apache.commons.lang.NullArgumentException; import org.apache.commons.lang.StringUtils; /** @@ -71,7 +70,7 @@ * @author Matthew Hawthorne * @author Gary Gregory * @since 2.0 - * @version $Id: NumberUtils.java,v 1.8 2003/07/28 21:37:32 scolebourne Exp $ + * @version $Id: NumberUtils.java,v 1.9 2003/07/31 23:45:28 scolebourne Exp $ */ public class NumberUtils { @@ -490,13 +489,13 @@ public static BigDecimal createBigDecimal(String str) { * * @param array an array, must not be null or empty * @return the minimum value in the array - * @throws NullArgumentException if array is null + * @throws IllegalArgumentException if array is null * @throws IllegalArgumentException if array is empty */ public static long min(long[] array) { // Validates input if (array == null) { - throw new NullArgumentException("Array"); + throw new IllegalArgumentException("The Array must not be null"); } else if (array.length == 0) { throw new IllegalArgumentException("Array cannot be empty."); } @@ -517,13 +516,13 @@ public static long min(long[] array) { * * @param array an array, must not be null or empty * @return the minimum value in the array - * @throws NullArgumentException if array is null + * @throws IllegalArgumentException if array is null * @throws IllegalArgumentException if array is empty */ public static int min(int[] array) { // Validates input if (array == null) { - throw new NullArgumentException("Array"); + throw new IllegalArgumentException("The Array must not be null"); } else if (array.length == 0) { throw new IllegalArgumentException("Array cannot be empty."); } @@ -544,13 +543,13 @@ public static int min(int[] array) { * * @param array an array, must not be null or empty * @return the minimum value in the array - * @throws NullArgumentException if array is null + * @throws IllegalArgumentException if array is null * @throws IllegalArgumentException if array is empty */ public static short min(short[] array) { // Validates input if (array == null) { - throw new NullArgumentException("Array"); + throw new IllegalArgumentException("The Array must not be null"); } else if (array.length == 0) { throw new IllegalArgumentException("Array cannot be empty."); } @@ -571,13 +570,13 @@ public static short min(short[] array) { * * @param array an array, must not be null or empty * @return the minimum value in the array - * @throws NullArgumentException if array is null + * @throws IllegalArgumentException if array is null * @throws IllegalArgumentException if array is empty */ public static double min(double[] array) { // Validates input if (array == null) { - throw new NullArgumentException("Array"); + throw new IllegalArgumentException("The Array must not be null"); } else if (array.length == 0) { throw new IllegalArgumentException("Array cannot be empty."); } @@ -598,13 +597,13 @@ public static double min(double[] array) { * * @param array an array, must not be null or empty * @return the minimum value in the array - * @throws NullArgumentException if array is null + * @throws IllegalArgumentException if array is null * @throws IllegalArgumentException if array is empty */ public static float min(float[] array) { // Validates input if (array == null) { - throw new NullArgumentException("Array"); + throw new IllegalArgumentException("The Array must not be null"); } else if (array.length == 0) { throw new IllegalArgumentException("Array cannot be empty."); } @@ -627,13 +626,13 @@ public static float min(float[] array) { * * @param array an array, must not be null or empty * @return the minimum value in the array - * @throws NullArgumentException if array is null + * @throws IllegalArgumentException if array is null * @throws IllegalArgumentException if array is empty */ public static long max(long[] array) { // Validates input if (array == null) { - throw new NullArgumentException("Array"); + throw new IllegalArgumentException("The Array must not be null"); } else if (array.length == 0) { throw new IllegalArgumentException("Array cannot be empty."); } @@ -654,13 +653,13 @@ public static long max(long[] array) { * * @param array an array, must not be null or empty * @return the minimum value in the array - * @throws NullArgumentException if array is null + * @throws IllegalArgumentException if array is null * @throws IllegalArgumentException if array is empty */ public static int max(int[] array) { // Validates input if (array == null) { - throw new NullArgumentException("Array"); + throw new IllegalArgumentException("The Array must not be null"); } else if (array.length == 0) { throw new IllegalArgumentException("Array cannot be empty."); } @@ -681,13 +680,13 @@ public static int max(int[] array) { * * @param array an array, must not be null or empty * @return the minimum value in the array - * @throws NullArgumentException if array is null + * @throws IllegalArgumentException if array is null * @throws IllegalArgumentException if array is empty */ public static short max(short[] array) { // Validates input if (array == null) { - throw new NullArgumentException("Array"); + throw new IllegalArgumentException("The Array must not be null"); } else if (array.length == 0) { throw new IllegalArgumentException("Array cannot be empty."); } @@ -708,13 +707,13 @@ public static short max(short[] array) { * * @param array an array, must not be null or empty * @return the minimum value in the array - * @throws NullArgumentException if array is null + * @throws IllegalArgumentException if array is null * @throws IllegalArgumentException if array is empty */ public static double max(double[] array) { // Validates input if (array== null) { - throw new NullArgumentException("Array"); + throw new IllegalArgumentException("The Array must not be null"); } else if (array.length == 0) { throw new IllegalArgumentException("Array cannot be empty."); } @@ -735,13 +734,13 @@ public static double max(double[] array) { * * @param array an array, must not be null or empty * @return the minimum value in the array - * @throws NullArgumentException if array is null + * @throws IllegalArgumentException if array is null * @throws IllegalArgumentException if array is empty */ public static float max(float[] array) { // Validates input if (array == null) { - throw new NullArgumentException("Array"); + throw new IllegalArgumentException("The Array must not be null"); } else if (array.length == 0) { throw new IllegalArgumentException("Array cannot be empty."); }