harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Deakin (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-6307) [classlib][luni] java.net.HttpCookie.parse is not threadsafe
Date Fri, 18 Sep 2009 10:51:16 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-6307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12757099#action_12757099
] 

Oliver Deakin commented on HARMONY-6307:
----------------------------------------

Thanks for the patch! I ran the test case before applying the fix, but I see that even though
the asserts in the new threads are being triggered by the failing test cases, the test still
comes up as passing. This is because the asserts thrown in the threads do not propagate up
to the main thread, and thus are not caught by the test harness.

Perhaps something like [1] would do?

[1]
Index: HttpCookieTest.java
===================================================================
--- HttpCookieTest.java	(revision 815696)
+++ HttpCookieTest.java	(working copy)
@@ -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 + ";");



> [classlib][luni] java.net.HttpCookie.parse is not threadsafe
> ------------------------------------------------------------
>
>                 Key: HARMONY-6307
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6307
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: Java 6 branch, all platforms
>            Reporter: Catherine Hope
>            Assignee: Oliver Deakin
>         Attachments: 6307-patch.txt
>
>
> Static method java.net.HttpCookie.parse is not threadsafe in that calling this method
across multiple threads (but on thread local objects) will corrupt the resulting HttpCookie
objects.  The problem is the class is sharing static Setter objects for each cookie property,
to prevent the properties being set multiple times.  The fix is to make these object local.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message