javaee / javahelp

javahelp
Other
14 stars 15 forks source link

clone methods violate clone's contract #25

Open glassfishrobot opened 15 years ago

glassfishrobot commented 15 years ago

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]

glassfishrobot commented 15 years ago

Reported by kschaefe

glassfishrobot commented 15 years ago

Was assigned to javahelp-issues

glassfishrobot commented 7 years ago

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