Patch: super.clone() and CloneNotSupportedException

Mohan Embar gnustuff@thisiscool.com
Sun Jul 20 10:58:00 GMT 2003


Hi Anthony,

>gcj should complain about the following code, but it doesn't:
>
>public class bad implements Cloneable
>{
>  public Object clone ()
>    {
>      return super.clone ();
>    }
>}
>
>I've submitted a but report for this.
>
>
>The following changes were required in order to build libgcj with ecj. 
>Ok?

First off, congratulations for your work on ecj! It sounds way cool!

I have a couple of comments concerning this patch.

First off, and I know that this is beyond the scope of this patch, I
hate Cloneable and Object.clone() for all the reasons described
in Item 10 here:

http://developer.java.sun.com/developer/Books/effectivejava/Chapter3.pdf

Does anyone see a compelling reason not to scrap Cloneable and
clone() and simply provide explicit (possibly static) copy constructors?

Failing this, I think clone() of AbstractGraphicsState should at the very least be
protected and ideally, would omit the catch handler and simply declare a
throws CloneNotSupportedException in the method declaration. See pp. 50-51
of the above link. If you did the latter, you'd have to see if this breaks the
compilation of any subclasses (haven't tried this out).

As an aside, is there any way to copy a gnu.gcj.RawData instance in
Java without using clone()

-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/






More information about the Java-patches mailing list