Patch: super.clone() and CloneNotSupportedException
Anthony Green
green@redhat.com
Sun Jul 20 01:15:00 GMT 2003
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?
2003-07-19 Anthony Green <green@redhat.com>
* gnu/awt/j2d/AbstractGraphicsState.java (clone): Handle
CloneNotSupportedException.
* gnu/gcj/xlib/WindowAttributes.java (clone): Ditto.
* gnu/gcj/xlib/WMSizeHints.java (clone): Ditto.
* gnu/gcj/xlib/GC.java (clone): Ditto.
* gnu/awt/xlib/XGraphics.java (clone): Ditto.
* gnu/awt/j2d/Graphics2DImpl.java (clone): Ditto.
Index: gnu/awt/j2d/AbstractGraphicsState.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/awt/j2d/AbstractGraphicsState.java,v
retrieving revision 1.2
diff -u -2 -r1.2 AbstractGraphicsState.java
--- gnu/awt/j2d/AbstractGraphicsState.java 13 Feb 2001 18:48:46
-0000 1.2
+++ gnu/awt/j2d/AbstractGraphicsState.java 20 Jul 2003 01:03:42 -0000
@@ -129,5 +129,13 @@
public Object clone ()
{
- return super.clone ();
+ try
+ {
+ return super.clone ();
+ }
+ catch (CloneNotSupportedException ex)
+ {
+ // This should never happen.
+ throw new InternalError ();
+ }
}
}
Index: gnu/awt/j2d/Graphics2DImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/awt/j2d/Graphics2DImpl.java,v
retrieving revision 1.4
diff -u -2 -r1.4 Graphics2DImpl.java
--- gnu/awt/j2d/Graphics2DImpl.java 19 Feb 2003 09:46:42 -0000 1.4
+++ gnu/awt/j2d/Graphics2DImpl.java 20 Jul 2003 01:03:43 -0000
@@ -106,10 +106,18 @@
public Object clone()
{
- Graphics2DImpl gfxCopy = (Graphics2DImpl) super.clone();
- AbstractGraphicsState stateCopy =
- (AbstractGraphicsState) state.clone();
- gfxCopy.setState(stateCopy);
-
- return gfxCopy;
+ try
+ {
+ Graphics2DImpl gfxCopy = (Graphics2DImpl) super.clone();
+ AbstractGraphicsState stateCopy =
+ (AbstractGraphicsState) state.clone();
+ gfxCopy.setState(stateCopy);
+
+ return gfxCopy;
+ }
+ catch (CloneNotSupportedException ex)
+ {
+ // This should never happen.
+ throw new InternalError ();
+ }
}
Index: gnu/gcj/xlib/WindowAttributes.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/xlib/WindowAttributes.java,v
retrieving revision 1.2
diff -u -2 -r1.2 WindowAttributes.java
--- gnu/gcj/xlib/WindowAttributes.java 9 Mar 2002 16:25:13 -0000 1.2
+++ gnu/gcj/xlib/WindowAttributes.java 20 Jul 2003 01:03:43 -0000
@@ -44,13 +44,21 @@
public Object clone()
{
- WindowAttributes attributes = (WindowAttributes) super.clone();
- // In case of an exception before the stucture is copied.
- attributes.in = null;
- attributes.out = null;
-
- // FIXME: do anything else?
+ try
+ {
+ WindowAttributes attributes = (WindowAttributes) super.clone();
+ // In case of an exception before the stucture is copied.
+ attributes.in = null;
+ attributes.out = null;
- attributes.init(this);
- return attributes;
+ // FIXME: do anything else?
+
+ attributes.init(this);
+ return attributes;
+ }
+ catch (CloneNotSupportedException ex)
+ {
+ // This should never happen.
+ throw new InternalError ();
+ }
}
Index: gnu/gcj/xlib/WMSizeHints.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/xlib/WMSizeHints.java,v
retrieving revision 1.1
diff -u -2 -r1.1 WMSizeHints.java
--- gnu/gcj/xlib/WMSizeHints.java 22 Oct 2000 17:46:09 -0000 1.1
+++ gnu/gcj/xlib/WMSizeHints.java 20 Jul 2003 01:03:43 -0000
@@ -28,10 +28,18 @@
public Object clone() {
- WMSizeHints hints = (WMSizeHints) super.clone();
- // In case of an exception before the stucture is copied.
- hints.structure = null;
-
- hints.init(this);
- return hints;
+ try
+ {
+ WMSizeHints hints = (WMSizeHints) super.clone();
+ // In case of an exception before the stucture is copied.
+ hints.structure = null;
+
+ hints.init(this);
+ return hints;
+ }
+ catch (CloneNotSupportedException ex)
+ {
+ // This should never happen.
+ throw new InternalError ();
+ }
}
Index: gnu/gcj/xlib/GC.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/xlib/GC.java,v
retrieving revision 1.4
diff -u -2 -r1.4 GC.java
--- gnu/gcj/xlib/GC.java 12 Jun 2003 03:08:58 -0000 1.4
+++ gnu/gcj/xlib/GC.java 20 Jul 2003 01:03:43 -0000
@@ -37,13 +37,21 @@
public Object clone()
{
- GC gcClone = target.getGCFromCache ();
- if (gcClone==null)
- {
- gcClone = (GC) super.clone();
- gcClone.structure = null;
- }
- gcClone.initStructure(this);
- gcClone.updateClip();
- return gcClone;
+ try
+ {
+ GC gcClone = target.getGCFromCache ();
+ if (gcClone==null)
+ {
+ gcClone = (GC) super.clone();
+ gcClone.structure = null;
+ }
+ gcClone.initStructure(this);
+ gcClone.updateClip();
+ return gcClone;
+ }
+ catch (CloneNotSupportedException ex)
+ {
+ // This should never happen.
+ throw new InternalError ();
+ }
}
Index: gnu/awt/xlib/XGraphics.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/awt/xlib/XGraphics.java,v
retrieving revision 1.4
diff -u -2 -r1.4 XGraphics.java
--- gnu/awt/xlib/XGraphics.java 12 Jun 2003 03:08:58 -0000 1.4
+++ gnu/awt/xlib/XGraphics.java 20 Jul 2003 01:03:43 -0000
@@ -47,8 +47,16 @@
public Object clone()
{
- XGraphics gfxCopy = (XGraphics) super.clone();
- gfxCopy.context = context.create();
-
- return gfxCopy;
+ try
+ {
+ XGraphics gfxCopy = (XGraphics) super.clone();
+ gfxCopy.context = context.create();
+
+ return gfxCopy;
+ }
+ catch (CloneNotSupportedException ex)
+ {
+ // This should never happen.
+ throw new InternalError ();
+ }
}
--
Anthony Green <green@redhat.com>
Red Hat, Inc.
More information about the Java-patches
mailing list