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

Covariance bug for multiple interface inheritance

    XMLWordPrintable

Details

    • x86
    • windows_xp

    Description

      FULL PRODUCT VERSION :
      java version "1.6.0_17"
      Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
      Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP Professional, Version 2002, Service Pack 3

      A DESCRIPTION OF THE PROBLEM :
      Cannot compile Java code. The problem can be demonstrated as follows:

      An interface AB extends interfaces A and B both providing a covariant override of the clone() method. AB is also cloneable and its clone() method is overriden to return AB. The example code below illustrates this simple relationship.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Simply compile example code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should compile with the JDK compiler.
      Note that the Eclipse Java compiler compiles without errors or warnings.
      ACTUAL -
      Does not compile with the JDK compiler.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Information:Compilation completed with 1 error and 0 warnings
      Information:1 error
      Information:0 warnings
      C:\Dokumente und Einstellungen\Norman\JavaProjects\ceres-0.x\ceres-ui\src\test\java\com\bc\CovarianceTest.java
          Error:Error:line (13)types com.bc.CovarianceTest.B and com.bc.CovarianceTest.A are incompatible; both define clone(), but with unrelated return types

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package com.bc;

      public class CovarianceTest {

          public interface A extends Cloneable {
              public A clone();
          }

          public interface B extends Cloneable {
              public B clone();
          }

          public interface AB extends A, B {
              @Override
              public AB clone();
          }
      }

      ---------- END SOURCE ----------

      Attachments

        Activity

          People

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: