You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by bu...@apache.org on 2010/08/16 15:19:38 UTC

DO NOT REPLY [Bug 49754] New: [PATCH] Bring clone() in line with the recommendations in Object.clone()

https://issues.apache.org/bugzilla/show_bug.cgi?id=49754

           Summary: [PATCH] Bring clone() in line with the recommendations
                    in Object.clone()
           Product: Fop
           Version: 1.1dev
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: general
        AssignedTo: fop-dev@xmlgraphics.apache.org
        ReportedBy: spepping@apache.org


Created an attachment (id=25892)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=25892)
patch

This patch tries to fix the problems with the clone method as reported by
findbugs.

The fix is not straightforward. The current design deviates from the design
advocated by findbugs and the documentation of Object.clone(). It is sometimes
hard to guess the author's intention with the original clone method. Often the
clone is not completely deep; was this intentional or not? This patch makes
almost always deep copies, esp. in the subclasses of AreaTreeObject. This patch
passes all existing junit tests. Since findbugs requires more memory than my
machine has, I could not check if this patch removes all findbugs warnings for
clone.

How does clone differ from a copy constructor? Is it a bad situation to have
both a clone method and a copy constructor? Is it advisable to delete one of
them?

Because it is not straightforward, I submit this as a patch, instead of
committing it right away.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 49754] [PATCH] Bring clone() in line with the recommendations in Object.clone()

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49754

--- Comment #1 from Andreas L. Delmelle <ad...@apache.org> 2011-01-09 17:34:33 EST ---
(In reply to comment #0)
> 
> How does clone differ from a copy constructor? 

Mainly in the returned type. The result of a call to a copy constructor will
always be statically typed as the class where the constructor is defined. This
can lead to undesired results if the parameter is an instance of a subclass,
unless either:
a) the copy constructor is overridden in the subclass, which makes it awkward
to use vs. a single clone() method, or
b) the superclass' copy constructor contains some convoluted reflection logic
to test the parameter for its runtime type (but that would not take into
account possible subclasses out of your control)

clone(), on the other hand, is guaranteed to always return an instance of
Object, whose actual runtime type is (recommended to be) identical to that of
the instance for which it is called. In practice, Object.clone() respect this,
so having the Cloneable interface is enough for basic shallow cloning to be
enabled. The key advantage being that in your code it takes only a single
statement to invoke. The Java runtime will sort out which implementation to
use.

> Is it a bad situation to have both a clone method and a copy constructor?
> Is it advisable to delete one of them?

Both have their merits. From the point of view of an internal API, if the class
itself is final or you know in advance precisely which type(s) you need, a set
of copy constructors will generally be more appropriate. From the point of view
of an external API, where you need to accommodate potential subclasses, clone()
would be the way to go.
Looking closer at the code, especially for the AreaTreeObject subclasses,
clone() is only used by the Java2DRenderer, and even then, it is only called
externally on PageViewport. All the other calls to clone() happen internally in
the area package. There seems to be no hard requirement at all to have a public
API to create clones/copies of all the other object classes, so there I would
be more inclined to opt for protected copy constructors, or an optimized set of
static factory-like methods, maybe...?

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 49754] [PATCH] Bring clone() in line with the recommendations in Object.clone()

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49754

Glenn Adams <gl...@skynav.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P5

--- Comment #3 from Glenn Adams <gl...@skynav.com> 2012-04-08 09:05:54 UTC ---
lower priority to P5, since this patch would not have an impact on features or
performance

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 49754] [PATCH] Bring clone() in line with the recommendations in Object.clone()

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49754

--- Comment #4 from Glenn Adams <gl...@skynav.com> 2012-04-08 09:11:11 UTC ---
increase priority due to presence of a patch

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 49754] [PATCH] Bring clone() in line with the recommendations in Object.clone()

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49754

--- Comment #2 from Glenn Adams <gl...@skynav.com> 2012-04-07 01:43:51 UTC ---
resetting P2 open bugs to P3 pending further review

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 49754] [PATCH] Bring clone() in line with the recommendations in Object.clone()

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49754

Glenn Adams <gl...@skynav.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P5                          |P2

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

[Bug 49754] [PATCH] Bring clone() in line with the recommendations in Object.clone()

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49754

--- Comment #6 from Luis Bernardo <lm...@gmail.com> ---
this patch introduced bug 53942 for which there already a patch (attachment
29465) that fixes it. looking at it the question I have is whether
MainReference should also implement its own clone() method which then would be
called by the BodyRegion.clone().

-- 
You are receiving this mail because:
You are the assignee for the bug.

DO NOT REPLY [Bug 49754] [PATCH] Bring clone() in line with the recommendations in Object.clone()

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49754

Glenn Adams <gl...@skynav.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P5

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 49754] [PATCH] Bring clone() in line with the recommendations in Object.clone()

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49754

Glenn Adams <gl...@skynav.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #5 from Glenn Adams <gl...@skynav.com> 2012-04-08 23:53:33 UTC ---
patch landed at http://svn.apache.org/viewvc?view=revision&revision=1311120
with a few minor changes; N.B. IFGraphicContext.clone was unable to employ
super.clone() at this time, so this remains a findbugs exclusion for now;

thanks simon!

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 49754] [PATCH] Bring clone() in line with the recommendations in Object.clone()

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49754

Glenn Adams <gl...@skynav.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P3

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.