Author: erans
Date: Mon Jun 28 12:01:35 2010
New Revision: 958551

URL: http://svn.apache.org/viewvc?rev=958551&view=rev
Log:
MATH-361.
Added a check to avoid triggering a "NullPointerException" if the argument
list is "null".
Added unit tests.

Added:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/DimensionMismatchExceptionTest.java
   (with props)
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NotPositiveExceptionTest.java
   (with props)
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NotStrictlyPositiveExceptionTest.java
   (with props)
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/OutOfRangeExceptionTest.java
   (with props)
Modified:
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java?rev=958551&r1=958550&r2=958551&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
 Mon Jun 28 12:01:35 2010
@@ -72,11 +72,13 @@ public class MathIllegalArgumentExceptio
      */
     private List<Object> flatten(Object[] array) {
         final List<Object> list = new ArrayList<Object>();
-        for (Object o : array) {
-            if (o instanceof Object[]) {
-                list.addAll(flatten((Object[]) o));
-            } else {
-                list.add(o);
+        if (array != null) {
+            for (Object o : array) {
+                if (o instanceof Object[]) {
+                    list.addAll(flatten((Object[]) o));
+                } else {
+                    list.add(o);
+                }
             }
         }
         return list;

Added: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/DimensionMismatchExceptionTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/DimensionMismatchExceptionTest.java?rev=958551&view=auto
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/DimensionMismatchExceptionTest.java
 (added)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/DimensionMismatchExceptionTest.java
 Mon Jun 28 12:01:35 2010
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test for {...@link DimensionMismatchException}.
+ * 
+ * @version $Revision$ $Date$ 
+ */
+public class DimensionMismatchExceptionTest {
+    @Test
+    public void testAccessors() {
+        final DimensionMismatchException e = new DimensionMismatchException(1, 
2);
+        Assert.assertEquals(1, e.getArgument());
+        Assert.assertEquals(2, e.getDimension());
+    }
+}

Propchange: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/DimensionMismatchExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NotPositiveExceptionTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NotPositiveExceptionTest.java?rev=958551&view=auto
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NotPositiveExceptionTest.java
 (added)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NotPositiveExceptionTest.java
 Mon Jun 28 12:01:35 2010
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test for {...@link NotPositiveException}.
+ * 
+ * @version $Revision$ $Date$ 
+ */
+public class NotPositiveExceptionTest {
+    @Test
+    public void testAccessors() {
+        final NotPositiveException e = new NotPositiveException(-1);
+        Assert.assertEquals(-1, e.getArgument());
+    }
+}

Propchange: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NotPositiveExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NotStrictlyPositiveExceptionTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NotStrictlyPositiveExceptionTest.java?rev=958551&view=auto
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NotStrictlyPositiveExceptionTest.java
 (added)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NotStrictlyPositiveExceptionTest.java
 Mon Jun 28 12:01:35 2010
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test for {...@link NotStrictlyPositiveException}.
+ * 
+ * @version $Revision$ $Date$ 
+ */
+public class NotStrictlyPositiveExceptionTest {
+    @Test
+    public void testAccessors() {
+        final NotStrictlyPositiveException e = new 
NotStrictlyPositiveException(0);
+        Assert.assertEquals(0, e.getArgument());
+    }
+}

Propchange: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/NotStrictlyPositiveExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/OutOfRangeExceptionTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/OutOfRangeExceptionTest.java?rev=958551&view=auto
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/OutOfRangeExceptionTest.java
 (added)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/OutOfRangeExceptionTest.java
 Mon Jun 28 12:01:35 2010
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test for {...@link OutOfRangeException}.
+ * 
+ * @version $Revision$ $Date$ 
+ */
+public class OutOfRangeExceptionTest {
+    @Test
+    public void testAccessors() {
+        final OutOfRangeException e = new OutOfRangeException(-1, 0, 2);
+        Assert.assertEquals(-1, e.getArgument());
+        Assert.assertEquals(0, e.getLo());
+        Assert.assertEquals(2, e.getHi());
+    }
+}

Propchange: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/OutOfRangeExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to