Threads should not be Cloneable
David Schlosnagle
schlosna at gmail.com
Fri Aug 13 16:06:25 UTC 2010
On Fri, Aug 13, 2010 at 10:15 AM, Chris Hegarty
<chris.hegarty at oracle.com> wrote:
> OK, so we'll allow subclasses to crate their own clones but disallow access
> to the default Object.clone implementation. I don't have a particular
> problem with this.
>
> -Chris.
I may be missing something, but if java.lang.Thread.clone() will now
throw CloneNotSupportedException, how would subtypes properly
implement Cloneable? If the subtype calls super.clone(),
CloneNotSupportedException will be thrown. If the subtype calls its
own constructor, that would seem to violate the clone contract for any
further subtypes. I think it would seem best to either strictly forbid
cloning all j.l.Thread and subtypes by making j.l.Thread.clone() final
and always throw CloneNotSupportedException, or if you are concerned
about violating source compatibility by making j.l.Thread.clone()
final then you could make it throw CloneNotSupportedException for
threadStatus != 0 (i.e. NEW threads).
- Dave
More information about the core-libs-dev
mailing list