changeset 5250:3bfebedb549f

7045655: An empty InMemoryCookieStore should not return true for removeAll Summary: CookieStore.removeAll() should return false for an empty CookieStore Reviewed-by: chegar
author khazra
date Thu, 15 Mar 2012 13:21:16 -0700
parents cfe2328912b3
children e48136bb8fdd
files src/share/classes/java/net/InMemoryCookieStore.java test/java/net/CookieHandler/NullUriCookieTest.java
diffstat 2 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/net/InMemoryCookieStore.java	Thu Mar 15 16:46:47 2012 +0000
+++ b/src/share/classes/java/net/InMemoryCookieStore.java	Thu Mar 15 13:21:16 2012 -0700
@@ -207,6 +207,9 @@
     public boolean removeAll() {
         lock.lock();
         try {
+            if (cookieJar.isEmpty()) {
+                return false;
+            }
             cookieJar.clear();
             domainIndex.clear();
             uriIndex.clear();
--- a/test/java/net/CookieHandler/NullUriCookieTest.java	Thu Mar 15 16:46:47 2012 +0000
+++ b/test/java/net/CookieHandler/NullUriCookieTest.java	Thu Mar 15 13:21:16 2012 -0700
@@ -23,8 +23,9 @@
 
 /*
  * @test
- * @bug 6953455
+ * @bug 6953455 7045655
  * @summary CookieStore.add() cannot handle null URI parameter
+ *     and An empty InMemoryCookieStore should not return true for removeAll
  */
 
 import java.net.CookieManager;
@@ -44,6 +45,11 @@
     static void checkCookieNullUri() throws Exception {
         //get a cookie store implementation and add a cookie to the store with null URI
         CookieStore cookieStore = (new CookieManager()).getCookieStore();
+        //Check if removeAll() retrurns false on an empty CookieStore
+        if (cookieStore.removeAll()) {
+            fail = true;
+        }
+        checkFail("removeAll on empty store should return false");
         HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
         cookie.setDomain("foo.com");
         cookieStore.add(null, cookie);