[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug classpath/24858] New: clone does not work with ThreadLocal
From: |
subanark at gmail dot com |
Subject: |
[Bug classpath/24858] New: clone does not work with ThreadLocal |
Date: |
14 Nov 2005 19:51:01 -0000 |
Although ThreadLocal does not allow cloning by itsself, subclasses can enable
this. The implementation of ThreadLocal uses a private key to retrieve data
from the WeakHashMap. clone() copies this key and causes cloned ThreadLocals to
mirror each other rather than being a new unique ThreadLocal. Note that Sun's
implementation is also broken, just in a different way, in that the new cloned
threadlocal does not have its value set.
Sample:
public class Test extends ThreadLocal implements Cloneable
{
public static void main(String[] args) throws Exception
{
Test t = new Test();
t.set("Test");
Test t2 = (Test) t.clone();
System.out.println(t2.get());
t.set("Test2");
System.out.println(t2.get());
}
}
classpath's output:
Test
Test2
Sun's output:
null
null
Expected output:
Test
Test
--
Summary: clone does not work with ThreadLocal
Product: classpath
Version: 0.18
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: classpath
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: subanark at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24858
- [Bug classpath/24858] New: clone does not work with ThreadLocal,
subanark at gmail dot com <=