harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r418316 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Arrays.java test/java/tests/api/java/util/ArraysTest.java
Date Fri, 30 Jun 2006 16:03:32 GMT
Author: gharley
Date: Fri Jun 30 09:03:31 2006
New Revision: 418316

URL: http://svn.apache.org/viewvc?rev=418316&view=rev
Log:
HARMONY 710 : compatibility: exception order Harmony Arrays.sort([],int int) throw ArrayIndexOutOfBoundsException
while RI IllegalArgumentException

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArraysTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java?rev=418316&r1=418315&r2=418316&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java
Fri Jun 30 09:03:31 2006
@@ -1443,17 +1443,20 @@
         if (array == null) {
             throw new NullPointerException();
         }
-        if (start >= 0 && end <= array.length) {
-            if (start <= end) {
-                sort(start, end, array);
-            } else {
-                throw new IllegalArgumentException();
-            }
-        } else {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
+        sort(start, end, array);
     }
 
+    private static void checkBounds(int arrLength, int start, int end) {
+        if (start > end) {
+        	throw new IllegalArgumentException("fromIndex(" + start 
+        				+ ") > toIndex(" + end + ")");
+        }
+        if (start < 0 || end > arrLength) {
+        	throw new ArrayIndexOutOfBoundsException();
+        }
+    }
+    
     private static void sort(int start, int end, byte[] array) {
         byte temp;
         int length = end - start;
@@ -1562,15 +1565,8 @@
         if (array == null) {
             throw new NullPointerException();
         }
-        if (start >= 0 && end <= array.length) {
-            if (start <= end) {
-                sort(start, end, array);
-            } else {
-                throw new IllegalArgumentException();
-            }
-        } else {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
+        sort(start, end, array);
     }
 
     private static void sort(int start, int end, char[] array) {
@@ -1686,15 +1682,8 @@
         if (array == null) {
             throw new NullPointerException();
         }
-        if (start >= 0 && end <= array.length) {
-            if (start <= end) {
-                sort(start, end, array);
-            } else {
-                throw new IllegalArgumentException();
-            }
-        } else {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
+        sort(start, end, array);
     }
 
     private static void sort(int start, int end, double[] array) {
@@ -1810,15 +1799,8 @@
         if (array == null) {
             throw new NullPointerException();
         }
-        if (start >= 0 && end <= array.length) {
-            if (start <= end) {
-                sort(start, end, array);
-            } else {
-                throw new IllegalArgumentException();
-            }
-        } else {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
+        sort(start, end, array);
     }
 
     private static void sort(int start, int end, float[] array) {
@@ -1929,15 +1911,8 @@
         if (array == null) {
             throw new NullPointerException();
         }
-        if (start >= 0 && end <= array.length) {
-            if (start <= end) {
-                sort(start, end, array);
-            } else {
-                throw new IllegalArgumentException();
-            }
-        } else {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
+        sort(start, end, array);
     }
 
     private static void sort(int start, int end, int[] array) {
@@ -2048,15 +2023,8 @@
         if (array == null) {
             throw new NullPointerException();
         }
-        if (start >= 0 && end <= array.length) {
-            if (start <= end) {
-                sort(start, end, array);
-            } else {
-                throw new IllegalArgumentException();
-            }
-        } else {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
+        sort(start, end, array);
     }
 
     private static void sort(int start, int end, long[] array) {
@@ -2174,15 +2142,8 @@
         if (array == null) {
             throw new NullPointerException();
         }
-        if (start >= 0 && end <= array.length) {
-            if (start <= end) {
-                sort(start, end, array);
-            } else {
-                throw new IllegalArgumentException();
-            }
-        } else {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
+        sort(start, end, array);
     }
 
     @SuppressWarnings("unchecked")
@@ -2245,15 +2206,8 @@
         if (array == null) {
             throw new NullPointerException();
         }
-        if (start >= 0 && end <= array.length) {
-            if (start <= end) {
-                sort(start, end, array, comparator);
-            } else {
-                throw new IllegalArgumentException();
-            }
-        } else {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
+        sort(start, end, array, comparator);
     }
 
     private static <T> void sort(int start, int end, T[] array,
@@ -2341,15 +2295,8 @@
         if (array == null) {
             throw new NullPointerException();
         }
-        if (start >= 0 && end <= array.length) {
-            if (start <= end) {
-                sort(start, end, array);
-            } else {
-                throw new IllegalArgumentException();
-            }
-        } else {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
+        sort(start, end, array);
     }
 
     private static void sort(int start, int end, short[] array) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArraysTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArraysTest.java?rev=418316&r1=418315&r2=418316&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArraysTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArraysTest.java
Fri Jun 30 09:03:31 2006
@@ -771,6 +771,32 @@
 		for (int counter = endIndex; counter < arraySize; counter++)
 			assertTrue("Array modified outside of bounds",
 					reversedArray[counter] == originalReversedArray[counter]);
+
+		//exception testing
+		try {
+			Arrays.sort(reversedArray, startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
+
+        try {
+			Arrays.sort(reversedArray, -1, startIndex);
+            fail("ArrayIndexOutOfBoundsException expected (1)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+
+		try {
+			Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
+            fail("ArrayIndexOutOfBoundsException expected (2)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+		
+		//exception order testing
+		try {
+			Arrays.sort(new byte[1], startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
 	}
 
 	/**
@@ -812,6 +838,31 @@
 			assertTrue("Array modified outside of bounds",
 					reversedArray[counter] == originalReversedArray[counter]);
 
+		//exception testing
+		try {
+			Arrays.sort(reversedArray, startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
+
+		try {
+			Arrays.sort(reversedArray, -1, startIndex);
+            fail("ArrayIndexOutOfBoundsException expected (1)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+        
+		try {
+			Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
+            fail("ArrayIndexOutOfBoundsException expected (2)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+
+		//exception order testing
+		try {
+			Arrays.sort(new char[1], startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
 	}
 
 	/**
@@ -876,6 +927,31 @@
 			assertTrue("Array modified outside of bounds",
 					reversedArray[counter] == originalReversedArray[counter]);
 
+		//exception testing
+		try {
+			Arrays.sort(reversedArray, startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
+
+		try {
+			Arrays.sort(reversedArray, -1, startIndex);
+            fail("ArrayIndexOutOfBoundsException expected (1)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+
+		try {
+			Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
+            fail("ArrayIndexOutOfBoundsException expected (2)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+		
+		//exception order testing
+		try {
+			Arrays.sort(new double[1], startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
 	}
 
 	/**
@@ -939,6 +1015,32 @@
 		for (int counter = endIndex; counter < arraySize; counter++)
 			assertTrue("Array modified outside of bounds",
 					reversedArray[counter] == originalReversedArray[counter]);
+
+		//exception testing
+		try {
+			Arrays.sort(reversedArray, startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
+
+        try {
+			Arrays.sort(reversedArray, -1, startIndex);
+            fail("ArrayIndexOutOfBoundsException expected (1)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+        
+		try {
+			Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
+            fail("ArrayIndexOutOfBoundsException expected (2)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+		
+		//exception order testing
+		try {
+			Arrays.sort(new float[1], startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
 	}
 
 	/**
@@ -979,6 +1081,31 @@
 			assertTrue("Array modified outside of bounds",
 					reversedArray[counter] == originalReversedArray[counter]);
 
+		//exception testing
+		try {
+			Arrays.sort(reversedArray, startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
+
+        try {
+			Arrays.sort(reversedArray, -1, startIndex);
+            fail("ArrayIndexOutOfBoundsException expected (1)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+        
+		try {
+			Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
+            fail("ArrayIndexOutOfBoundsException expected (2)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+		
+		//exception order testing
+		try {
+			Arrays.sort(new int[1], startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
 	}
 
 	/**
@@ -1020,6 +1147,31 @@
 			assertTrue("Array modified outside of bounds",
 					reversedArray[counter] == originalReversedArray[counter]);
 
+		//exception testing
+		try {
+			Arrays.sort(reversedArray, startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
+
+        try {
+			Arrays.sort(reversedArray, -1, startIndex);
+            fail("ArrayIndexOutOfBoundsException expected (1)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+
+		try {
+			Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
+            fail("ArrayIndexOutOfBoundsException expected (2)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+        
+		//exception order testing
+		try {
+			Arrays.sort(new long[1], startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
 	}
 
 	/**
@@ -1061,6 +1213,32 @@
 		for (int counter = endIndex; counter < arraySize; counter++)
 			assertTrue("Array modified outside of bounds",
 					reversedArray[counter] == originalReversedArray[counter]);
+
+		//exception testing
+		try {
+			Arrays.sort(reversedArray, startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
+        
+		try {
+			Arrays.sort(reversedArray, -1, startIndex);
+            fail("ArrayIndexOutOfBoundsException expected (1)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+
+        try {
+			Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
+            fail("ArrayIndexOutOfBoundsException expected (2)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+		
+		//exception order testing
+		try {
+			Arrays.sort(new Object[1], startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
 	}
 
 	/**
@@ -1140,6 +1318,32 @@
 		for (int counter = endIndex; counter < arraySize; counter++)
 			assertTrue("Array modified outside of bounds",
 					reversedArray[counter] == originalReversedArray[counter]);
+	
+		//exception testing
+		try {
+			Arrays.sort(reversedArray, startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
+        
+		try {
+			Arrays.sort(reversedArray, -1, startIndex);
+            fail("ArrayIndexOutOfBoundsException expected (1)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+        
+		try {
+			Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
+            fail("ArrayIndexOutOfBoundsException expected (2)");
+		} catch (ArrayIndexOutOfBoundsException ignore) {
+		}
+		
+		//exception order testing
+		try {
+			Arrays.sort(new short[1], startIndex + 1, startIndex);
+            fail("IllegalArgumentException expected");
+		} catch (IllegalArgumentException ignore) {
+		}
 	}
 
     /**



Mime
View raw message