Skip to content
This repository was archived by the owner on Jan 30, 2019. It is now read-only.
This repository was archived by the owner on Jan 30, 2019. It is now read-only.

clone methods violate clone's contract #25

Open

Description

@glassfishrobot

Most (all?) clone methods are not properly written. Consider the following
example:

public class MyHTMLIndexerKit extends HTMLIndexerKit {}

(new MyHTMLIndexKit().clone() instanceof MyHTMLIndexerKit) == false

If I override the clone method (correctly by calling super):

public class MyHTMLIndexerKit extends HTMLIndexerKit {
public void clone() throws CloneNotSupportedException {
//causes a ClassCastException
MyHTMLIndexKit clone = null;

try

{ clone = (MyHTMLIndexerKit) super.clone(); }

catch (CloneNotSupportedException neverThrown)

{ //does nothing }

return clone;
}
}

Since clone is not properly implemented by HTMLIndexerKit, I can never properly
implement in a subclass.

So far, of all of the clone methods that I have inspected, none of them are
correctly implemented. They simply are returning a new instance of the class.

Environment

Operating System: All
Platform: All

Affected Versions

[current]

Activity

  1. glassfishrobot commented on Sep 19, 2008

    @glassfishrobot
    ContributorAuthor

    Reported by kschaefe

  2. glassfishrobot commented on Sep 19, 2008

    @glassfishrobot
    ContributorAuthor

    Was assigned to javahelp-issues

  3. glassfishrobot commented on Apr 26, 2017

    @glassfishrobot
    ContributorAuthor

    This issue was imported from java.net JIRA JAVAHELP-25

  4. added this to the milestone 1 milestone on Apr 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions