Author: luc
Date: Sun Dec  7 12:17:45 2008
New Revision: 724187

URL: http://svn.apache.org/viewvc?rev=724187&view=rev
Log:
fixed missing error checks

Modified:
    
commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java?rev=724187&r1=724186&r2=724187&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java
 Sun Dec  7 12:17:45 2008
@@ -321,9 +321,26 @@
                 throw MathRuntimeException.createIllegalStateException("first 
{0} columns are not initialized yet",
                                                                        new 
Object[] { column });
             }
-            data = new double[subMatrix.length][subMatrix[0].length];
+            final int nRows = subMatrix.length;
+            if (nRows == 0) {
+                throw 
MathRuntimeException.createIllegalArgumentException("matrix must have at least 
one row",
+                                                                          
null); 
+            }
+
+            final int nCols = subMatrix[0].length;
+            if (nCols == 0) {
+                throw 
MathRuntimeException.createIllegalArgumentException("matrix must have at least 
one column",
+                                                                          
null); 
+            }
+            data = new double[subMatrix.length][nCols];
             for (int i = 0; i < data.length; ++i) {
-                System.arraycopy(subMatrix[i], 0, data[i], 0, 
subMatrix[i].length);
+                if (subMatrix[i].length != nCols) {
+                    throw 
MathRuntimeException.createIllegalArgumentException("some rows have length {0} 
while others have length {1}",
+                                                                              
new Object[] {
+                                                                               
   nCols, subMatrix[i].length
+                                                                              
}); 
+                }
+                System.arraycopy(subMatrix[i], 0, data[i + row], column, 
nCols);
             }
         } else {
             super.setSubMatrix(subMatrix, row, column);


Reply via email to