harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r409607 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/ main/java/java/util/ test/java/tests/api/java/net/ test/java/tests/api/java/util/
Date Fri, 26 May 2006 09:25:03 GMT
Author: mloenko
Date: Fri May 26 02:25:03 2006
New Revision: 409607

URL: http://svn.apache.org/viewvc?rev=409607&view=rev
Log:
fixes and test for HARMONY-467
[classlib][luni] Harmony should follow the "Exception-throwing compatibility" guidelines

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLDecoder.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/LinkedList.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLDecoderTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArrayListTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLDecoder.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLDecoder.java?rev=409607&r1=409606&r2=409607&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLDecoder.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLDecoder.java
Fri May 26 02:25:03 2006
@@ -72,6 +72,13 @@
 		if (enc == null) {
 			throw new NullPointerException();
 		}
+
+		// If the given encoding is an empty string throw an exception.
+        if (enc.length() == 0) {
+            throw new UnsupportedEncodingException(Msg
+                    .getString("K00a5", "enc")); //$NON-NLS-1$
+        }
+
 		StringBuffer result = new StringBuffer(s.length());
 		ByteArrayOutputStream out = new ByteArrayOutputStream();
 		for (int i = 0; i < s.length();) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java?rev=409607&r1=409606&r2=409607&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java
Fri May 26 02:25:03 2006
@@ -136,65 +136,65 @@
 	}
 
 	/**
-	 * Inserts the objects in the specified Collection at the specified location
-	 * in this ArrayList. The objects are added in the order they are returned
-	 * from the Collection iterator.
-	 * 
-	 * @param location
-	 *            the index at which to insert
-	 * @param collection
-	 *            the Collection of objects
-	 * @return true if this ArrayList is modified, false otherwise
-	 * 
-	 * @exception IndexOutOfBoundsException
-	 *                when <code>location < 0 || >= size()</code>
-	 */
-	public boolean addAll(int location, Collection<? extends E> collection) {
-		int size = size();
-		int growSize = collection.size();
-		if (0 < location && location < size) {
-			if (array.length - size < growSize) {
-				growForInsert(location, growSize);
-			} else if ((location < size / 2 && firstIndex > 0)
-					|| lastIndex > array.length - growSize) {
-				int newFirst = firstIndex - growSize;
-				if (newFirst < 0) {
-					int index = location + firstIndex;
-					System.arraycopy(array, index, array, index - newFirst,
-							size - location);
-					lastIndex -= newFirst;
-					newFirst = 0;
-				}
-				System.arraycopy(array, firstIndex, array, newFirst, location);
-				firstIndex = newFirst;
-			} else {
-				int index = location + firstIndex;
-				System.arraycopy(array, index, array, index + growSize, size
-						- location);
-				lastIndex += growSize;
-			}
-		} else if (location == 0) {
-			if (firstIndex == 0)
-				growAtFront(growSize);
-			firstIndex -= growSize;
-		} else if (location == size) {
-			if (lastIndex > array.length - growSize)
-				growAtEnd(growSize);
-			lastIndex += growSize;
-		} else
-			throw new IndexOutOfBoundsException();
-
-		if (growSize > 0) {
-			Iterator it = collection.iterator();
-			int index = location + firstIndex;
-			int end = index + growSize;
-			while (index < end)
-				array[index++] = it.next();
-			modCount++;
-			return true;
-		}
-		return false;
-	}
+     * Inserts the objects in the specified Collection at the specified location
+     * in this ArrayList. The objects are added in the order they are returned
+     * from the Collection iterator.
+     * 
+     * @param location the index at which to insert
+     * @param collection the Collection of objects
+     * @return true if this ArrayList is modified, false otherwise
+     * 
+     * @exception IndexOutOfBoundsException when
+     *            <code>location < 0 || > size()</code>
+     */
+    public boolean addAll(int location, Collection<? extends E> collection) {
+        int size = size();
+        if (location < 0 || location > size) {
+            throw new IndexOutOfBoundsException();
+        }
+        int growSize = collection.size();
+        if (0 < location && location < size) {
+            if (array.length - size < growSize) {
+                growForInsert(location, growSize);
+            } else if ((location < size / 2 && firstIndex > 0)
+                    || lastIndex > array.length - growSize) {
+                int newFirst = firstIndex - growSize;
+                if (newFirst < 0) {
+                    int index = location + firstIndex;
+                    System.arraycopy(array, index, array, index - newFirst,
+                            size - location);
+                    lastIndex -= newFirst;
+                    newFirst = 0;
+                }
+                System.arraycopy(array, firstIndex, array, newFirst, location);
+                firstIndex = newFirst;
+            } else {
+                int index = location + firstIndex;
+                System.arraycopy(array, index, array, index + growSize, size
+                        - location);
+                lastIndex += growSize;
+            }
+        } else if (location == 0) {
+            if (firstIndex == 0)
+                growAtFront(growSize);
+            firstIndex -= growSize;
+        } else if (location == size) {
+            if (lastIndex > array.length - growSize)
+                growAtEnd(growSize);
+            lastIndex += growSize;
+        }
+
+        if (growSize > 0) {
+            Iterator it = collection.iterator();
+            int index = location + firstIndex;
+            int end = index + growSize;
+            while (index < end)
+                array[index++] = it.next();
+            modCount++;
+            return true;
+        }
+        return false;
+    }
 
 	/**
 	 * Adds the objects in the specified Collection to this ArrayList.
@@ -299,8 +299,9 @@
 	 *                when <code>location < 0 || >= size()</code>
 	 */
 	public E get(int location) {
-		if (0 <= location && location < size())
+		if (0 <= location && location < size()) {
 			return (E)array[firstIndex + location];
+        }
 		throw new IndexOutOfBoundsException();
 	}
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/LinkedList.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/LinkedList.java?rev=409607&r1=409606&r2=409607&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/LinkedList.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/LinkedList.java
Fri May 26 02:25:03 2006
@@ -240,48 +240,49 @@
 	}
 
 	/**
-	 * Inserts the objects in the specified Collection at the specified location
-	 * in this LinkedList. The objects are added in the order they are returned
-	 * from the <code>Collection</code> iterator.
-	 * 
-	 * @param location
-	 *            the index at which to insert
-	 * @param collection
-	 *            the Collection of objects
-	 * @return true if this LinkedList is modified, false otherwise
-	 * 
-	 * @exception IndexOutOfBoundsException
-	 *                when <code>location < 0 || >= size()</code>
-	 */
-	public boolean addAll(int location, Collection collection) {
-		int adding = collection.size();
-		if (adding == 0)
-			return false;
-		if (0 <= location && location <= size) {
-			Link previous = voidLink;
-			if (location < (size / 2)) {
-				for (int i = 0; i < location; i++)
-					previous = previous.next;
-			} else {
-				for (int i = size; i >= location; i--)
-					previous = previous.previous;
-			}
-			Link next = previous.next;
+     * Inserts the objects in the specified Collection at the specified location
+     * in this LinkedList. The objects are added in the order they are returned
+     * from the <code>Collection</code> iterator.
+     * 
+     * @param location the index at which to insert
+     * @param collection the Collection of objects
+     * @return true if this LinkedList is modified, false otherwise
+     * 
+     * @exception IndexOutOfBoundsException when
+     *            <code>location < 0 || > size()</code>
+     */
+    public boolean addAll(int location, Collection collection) {
+        if (location < 0 || location > size) {
+            throw new IndexOutOfBoundsException();
+        }
+        int adding = collection.size();
+        if (adding == 0) {
+            return false;
+        }
+        Link previous = voidLink;
+        if (location < (size / 2)) {
+            for (int i = 0; i < location; i++) {
+                previous = previous.next;
+            }
+        } else {
+            for (int i = size; i >= location; i--) {
+                previous = previous.previous;
+            }
+        }
+        Link next = previous.next;
 
-			Iterator it = collection.iterator();
-			while (it.hasNext()) {
-				Link newLink = new Link(it.next(), previous, null);
-				previous.next = newLink;
-				previous = newLink;
-			}
-			previous.next = next;
-			next.previous = previous;
-			size += adding;
-			modCount++;
-			return true;
-		} else
-			throw new IndexOutOfBoundsException();
-	}
+        Iterator it = collection.iterator();
+        while (it.hasNext()) {
+            Link newLink = new Link(it.next(), previous, null);
+            previous.next = newLink;
+            previous = newLink;
+        }
+        previous.next = next;
+        next.previous = previous;
+        size += adding;
+        modCount++;
+        return true;
+    }
 
 	/**
 	 * Adds the objects in the specified Collection to this LinkedList.

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLDecoderTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLDecoderTest.java?rev=409607&r1=409606&r2=409607&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLDecoderTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLDecoderTest.java
Fri May 26 02:25:03 2006
@@ -15,6 +15,7 @@
 
 package tests.api.java.net;
 
+import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
 
@@ -55,7 +56,21 @@
 		}
 	}
 
-	/**
+    /**
+     * @tests java.net.URLDecoder#decode(java.lang.String, java.lang.String)
+     */
+    public void test_decodeLjava_lang_String_Ljava_lang_String() {
+        try {
+            URLDecoder.decode("", "");
+            fail("UnsupportedEncodingException expected");
+        } catch (UnsupportedEncodingException e) {
+            // expected
+        } catch (Exception e) {
+            assertEquals(UnsupportedEncodingException.class, e.getClass());
+        }
+    }
+
+    /**
 	 * Sets up the fixture, for example, open a network connection. This method
 	 * is called before a test is executed.
 	 */

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArrayListTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArrayListTest.java?rev=409607&r1=409606&r2=409607&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArrayListTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArrayListTest.java
Fri May 26 02:25:03 2006
@@ -16,6 +16,7 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -138,7 +139,22 @@
 		assertTrue("Incorrect size2: " + alist.size(), alist.size() == 210);
 	}
 
-	/**
+    /**
+     * @tests java.util.ArrayList#addAll(int, java.util.Collection)
+     */
+    public void test_addAllILjava_util_Collection_2() {
+        ArrayList obj = new ArrayList();
+        try {
+            obj.addAll((int) -1, (Collection) null);
+            fail("IndexOutOfBoundsException expected");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        } catch (Exception e) {
+            assertEquals(IndexOutOfBoundsException.class, e.getClass());
+        }
+    }
+
+    /**
 	 * @tests java.util.ArrayList#addAll(java.util.Collection)
 	 */
 	public void test_addAllLjava_util_Collection() {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java?rev=409607&r1=409606&r2=409607&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java
Fri May 26 02:25:03 2006
@@ -118,7 +118,22 @@
 		assertNull("e) List w/nulls not added correctly", ll.get(54));
 	}
 
-	/**
+    /**
+     * @tests java.util.LinkedList#addAll(int, java.util.Collection)
+     */
+    public void test_addAllILjava_util_Collection_2() {
+        LinkedList obj = new LinkedList();
+        try {
+            obj.addAll((int) -1, (Collection) null);
+            fail("IndexOutOfBoundsException expected");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        } catch (Exception e) {
+            assertEquals(IndexOutOfBoundsException.class, e.getClass());
+        }
+    }
+
+    /**
 	 * @tests java.util.LinkedList#addAll(java.util.Collection)
 	 */
 	public void test_addAllLjava_util_Collection() {



Mime
View raw message