Index: modules/luni/src/test/java/tests/api/java/net/URLDecoderTest.java
===================================================================
--- modules/luni/src/test/java/tests/api/java/net/URLDecoderTest.java (revision 406614)
+++ modules/luni/src/test/java/tests/api/java/net/URLDecoderTest.java (working copy)
@@ -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.
*/
Index: modules/luni/src/test/java/tests/api/java/util/ArrayListTest.java
===================================================================
--- modules/luni/src/test/java/tests/api/java/util/ArrayListTest.java (revision 406614)
+++ modules/luni/src/test/java/tests/api/java/util/ArrayListTest.java (working copy)
@@ -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() {
Index: modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java
===================================================================
--- modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java (revision 406614)
+++ modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java (working copy)
@@ -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() {
Index: modules/luni/src/main/java/java/net/URLDecoder.java
===================================================================
--- modules/luni/src/main/java/java/net/URLDecoder.java (revision 406614)
+++ modules/luni/src/main/java/java/net/URLDecoder.java (working copy)
@@ -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();) {
Index: modules/luni/src/main/java/java/util/ArrayList.java
===================================================================
--- modules/luni/src/main/java/java/util/ArrayList.java (revision 406614)
+++ modules/luni/src/main/java/java/util/ArrayList.java (working copy)
@@ -147,10 +147,13 @@
* @return true if this ArrayList is modified, false otherwise
*
* @exception IndexOutOfBoundsException
- * when location < 0 || >= size()
+ * when location < 0 || > size()
*/
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) {
@@ -181,8 +184,7 @@
if (lastIndex > array.length - growSize)
growAtEnd(growSize);
lastIndex += growSize;
- } else
- throw new IndexOutOfBoundsException();
+ }
if (growSize > 0) {
Iterator it = collection.iterator();
Index: modules/luni/src/main/java/java/util/LinkedList.java
===================================================================
--- modules/luni/src/main/java/java/util/LinkedList.java (revision 406614)
+++ modules/luni/src/main/java/java/util/LinkedList.java (working copy)
@@ -251,36 +251,39 @@
* @return true if this LinkedList is modified, false otherwise
*
* @exception IndexOutOfBoundsException
- * when location < 0 || >= size()
+ * when location < 0 || > size()
*/
public boolean addAll(int location, Collection collection) {
+ if (location < 0 || location > size) {
+ throw new IndexOutOfBoundsException();
+ }
int adding = collection.size();
- if (adding == 0)
+ 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;
+ }
+ 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;
}
/**