Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1227421

clone() and copy() methods are unsafe

    Details

    • Subcomponent:
    • Resolved In Build:
      1.0fcs
    • CPU:
      sparc
    • OS:
      solaris_2.4
    • Verification:
      Not verified

      Description

         > 3. copy/clone
         
         I agree that this needs to be fixed. I don't like the suggested
         fix though. I don't think it is a good idea to "magically" provide
         the native method implementation. What if instead we do the following.
         define an empty interface called Cloneable:
         
          interface Cloneable {}
         
         provide the following methods in class Object:
         
          public native Object clone(Cloneable obj);
          public native void copy(Cloneable from, Cloneable to);
         
         Note that these methods can only be used on objects that are
         declared to implement the Cloneable interface.

      Yes, this is a great solution. I would argue, however, that we should
      adopt this solution *only* for the clone method. The copy method is
      dangerous, misleadingly named, and not really used in practice anyway.
      I say, nuke it!

      --Guy

        Attachments

          Activity

            People

            • Assignee:
              fyellinsunw Frank Yellin (Inactive)
              Reporter:
              ahoffsunw Arthur Hoff (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: