harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r819498 - in /harmony/enhanced/classlib/branches/java6/modules/luni/src: main/java/java/net/HttpCookie.java test/api/common/org/apache/harmony/luni/tests/java/net/HttpCookieTest.java
Date Mon, 28 Sep 2009 11:30:02 GMT
Author: odeakin
Date: Mon Sep 28 11:30:02 2009
New Revision: 819498

URL: http://svn.apache.org/viewvc?rev=819498&view=rev
Log:
Apply fix and add test for HARMONY-6307 ([classlib][luni] java.net.HttpCookie.parse is not
threadsafe)

Modified:
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/net/HttpCookie.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpCookieTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/net/HttpCookie.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/net/HttpCookie.java?rev=819498&r1=819497&r2=819498&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/net/HttpCookie.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/net/HttpCookie.java
Mon Sep 28 11:30:02 2009
@@ -83,7 +83,7 @@
     private static Pattern ATTR_PATTERN1 = Pattern
             .compile("(,?[^;=]*)(?:=([^;,]*))?((?=.))?"); //$NON-NLS-1$
 
-    private static HashMap<String, Setter> attributeSet = new HashMap<String, Setter>();
+    private HashMap<String, Setter> attributeSet = new HashMap<String, Setter>();
 
     /**
      * A utility method used to check whether the host name is in a domain or
@@ -248,7 +248,7 @@
                     }
                 }
 
-                Setter setter = attributeSet.get(attrName.toLowerCase());
+                Setter setter = cookie.attributeSet.get(attrName.toLowerCase());
                 if (null == setter) {
                     throw new IllegalArgumentException();
                 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpCookieTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpCookieTest.java?rev=819498&r1=819497&r2=819498&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpCookieTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpCookieTest.java
Mon Sep 28 11:30:02 2009
@@ -897,7 +897,55 @@
         cookie = list.get(0);
         assertEquals(0, cookie.getVersion());
     }
+    
+    /**
+     * @tests java.net.HttpCookie#parse(String) on multiple threads
+     * Regression test for HARMONY-6307
+     * 
+     * @since 1.6
+     * 
+     */
+    class ParseThread extends Thread {
+        public AssertionError error = null;
+        public void run() {
+            try {
+                for (int i = 0; i < 200; i++) {
+                    List<HttpCookie> list = HttpCookie.parse("Set-cookie:PREF=test;path=/;domain=.b.c;");
+                    assertEquals(1, list.size());
+                    HttpCookie cookie = list.get(0);
+                    assertEquals(0, cookie.getVersion());
+                    assertEquals(".b.c", cookie.getDomain());
+                }
+            } catch (AssertionError e) {
+                error = e;
+            }
+        }
+    }
+
+    public void test_Parse_multipleThreads() throws InterruptedException {
+        ParseThread[] threads = new ParseThread[10];
+        // create threads
+        for (int i = 0; i < threads.length; i++) {
+            threads[i] = new ParseThread();
+        }
+        
+        // start threads
+        for (ParseThread thread : threads) {
+            thread.start();
+        }
+
+        // wait for threads to finish
+        for (ParseThread thread : threads) {
+            thread.join();
+        }
 
+        for (ParseThread thread : threads) {
+            if (thread.error != null) {
+                fail("Assertion thrown in thread "+thread+": "+thread.error);
+            }
+        }        
+    }
+    
     private void checkValidValue(String header, String value) {
         List<HttpCookie> list = HttpCookie
                 .parse(header + "name=" + value + ";");



Mime
View raw message