classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] Patch: FYI: Kernel.clone() fixlet


From: Tom Tromey
Subject: [cp-patches] Patch: FYI: Kernel.clone() fixlet
Date: 06 Aug 2004 17:37:57 -0600
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

I'm checking this in.

I found this by chance while looking at a Mauve compilation problem.
It is usually a mistake to use `new' in an implementation of clone(),
the reason being that this will return the wrong result for a
subclass.

This changes behavior slightly, in that the old code made a copy of
the float[], and the new code does not.  I think the new version is
just as correct, however, since the array is not ever modified, and it
is private so no subclass could modify it.

For this class, this is a lot of ado about nothing.  I doubt there is
a subclass of Kernel anywhere.

Tom

Index: ChangeLog
from  Tom Tromey  <address@hidden>

        * java/awt/image/Kernel.java (clone): Use super.clone().

Index: java/awt/image/Kernel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/image/Kernel.java,v
retrieving revision 1.1
diff -u -r1.1 Kernel.java
--- java/awt/image/Kernel.java 22 Jul 2004 19:45:38 -0000 1.1
+++ java/awt/image/Kernel.java 6 Aug 2004 23:48:17 -0000
@@ -131,6 +131,13 @@
    */
   public Object clone()
   {
-    return new Kernel(width, height, data);
+    try
+      {
+       return super.clone();
+      }
+    catch (CloneNotSupportedException e)
+      {
+        throw (Error) new InternalError().initCause(e); // Impossible
+      }
   }
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]