From 03c44e05dfba382804e6646df1767bb22b50f957 Mon Sep 17 00:00:00 2001 From: kuporific Date: Mon, 14 Apr 2014 20:34:56 -0400 Subject: [PATCH] IndexOutOfBoundsException, JSONArray#remove(int) List#remove(int) throws an IndexOutOfBoundsException when index is less than 0 or greater than or equal to the length of the list. The JSONArray#remove(int) method was not making the proper check on the index value. --- JSONArray.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/JSONArray.java b/JSONArray.java index 673a91927..3931dbf64 100644 --- a/JSONArray.java +++ b/JSONArray.java @@ -813,9 +813,8 @@ public JSONArray put(int index, Object value) throws JSONException { * was no value. */ public Object remove(int index) { - Object o = this.opt(index); - this.myArrayList.remove(index); - return o; + return (index < 0 || index >= this.length()) ? null : this.myArrayList + .remove(index); } /**