scolebourne 2003/07/31 16:55:57 Modified: lang/src/test/org/apache/commons/lang BooleanUtilsTest.java lang/src/java/org/apache/commons/lang BooleanUtils.java Log: Hide NPE from ArrayUtils as IAE Revision Changes Path 1.6 +9 -1 jakarta-commons/lang/src/test/org/apache/commons/lang/BooleanUtilsTest.java Index: BooleanUtilsTest.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/BooleanUtilsTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- BooleanUtilsTest.java 30 Jul 2003 22:21:39 -0000 1.5 +++ BooleanUtilsTest.java 31 Jul 2003 23:55:57 -0000 1.6 @@ -466,6 +466,13 @@ fail("Exception was not thrown for empty input."); } catch (IllegalArgumentException ex) {} } + + public void testXor_object_nullElementInput() { + try { + BooleanUtils.xor(new Boolean[] {null}); + fail("Exception was not thrown for null element input."); + } catch (IllegalArgumentException ex) {} + } public void testXor_object_validInput_2items() { assertTrue( @@ -565,6 +572,7 @@ Boolean.TRUE, Boolean.TRUE }) .booleanValue()); + } } 1.11 +14 -3 jakarta-commons/lang/src/java/org/apache/commons/lang/BooleanUtils.java Index: BooleanUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/BooleanUtils.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- BooleanUtils.java 31 Jul 2003 22:30:07 -0000 1.10 +++ BooleanUtils.java 31 Jul 2003 23:55:57 -0000 1.11 @@ -654,12 +654,23 @@ * * @param array an array of <code>Boolean<code>s * @return <code>true</code> if the xor is successful. - * @throws NullPointerException if <code>array</code> contains a <code>null</code> * @throws IllegalArgumentException if <code>array</code> is <code>null</code> * @throws IllegalArgumentException if <code>array</code> is empty. + * @throws IllegalArgumentException if <code>array</code> contains a <code>null</code> */ public static Boolean xor(Boolean[] array) { - return (xor(ArrayUtils.toPrimitive(array)) ? Boolean.TRUE : Boolean.FALSE); + if (array == null) { + throw new IllegalArgumentException("The Array must not be null"); + } else if (array.length == 0) { + throw new IllegalArgumentException("Array is empty"); + } + boolean[] primitive = null; + try { + primitive = ArrayUtils.toPrimitive(array); + } catch (NullPointerException ex) { + throw new IllegalArgumentException("The array must not conatin any null elements"); + } + return (xor(primitive) ? Boolean.TRUE : Boolean.FALSE); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]