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

Trying to clone() a Set causes a compile time error.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P5 P5
    • None
    • 1.3.0
    • core-libs



      Name: skT45625 Date: 05/08/2000


      java version "1.3.0rc3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc3-Z)
      Java HotSpot(TM) Client VM (build 1.3.0rc3-Z, mixed mode)


      I am trying to compile a class. At the beginning I have:

      public class DSForest implements Serializable {
        private Set reps;



      Later on I have:

        public Set getRepresentatives () {
          return reps.clone();
        }

      (Yes, it looks like this is exposing an implementation detail, but this class
      is for a specialized purpose in a project, and is not meant for re-use. A
      generic disjoint set forest won't do here.)

      The weirdest message results at compile time:

      src\pgd\companion\util\DSForest.java:91: clone() has protected access in
      java.lang.Object
          return reps.clone();

      This looks like a bug to me, perhaps a compiler bug, perhaps a bug in Object,
      and perhaps a bug with the Set.

      I used a HashSet for the Set; this is documented to be cloneable. In any case,
      what I expect to get when I take any Object and clone it is either a clone or a
      CloneNotSupportedException at runtime, never a compile time error. JDK 1.3 RC3
      seems to have broken something.

      Inspecting Object.clone() in the docs, it is indeed "protected" now, which is
      peculiar, but this access specifier should act exactly like "public" on an
      Object method, because every reference type is descended from Object! In
      particular, DSForest is an Object, so can call clone() on any Object, including
      the Set; this should be dispatched polymorphically to call HashSet's clone();
      since HashSet is Cloneable this should work perfectly, without even throwing a
      CloneNotSupported exception at runtime.
      (Review ID: 104537)
      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            skondamasunw Suresh Kondamareddy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: