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

Bug in covariant overrides when multiply inheriting interfaces

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 7.0se, 7
    • 6u31
    • tools
    • b31
    • x86
    • os_x

      FULL PRODUCT VERSION :
      java version "1.6.0_33"
      Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-10M3720)
      Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386

      A DESCRIPTION OF THE PROBLEM :
      Trying to compile this code:
         public interface A {
             A getIt();
         }

         public interface B {
             B getIt();
         }

         public interface C extends A, B {
             @Override
             C getIt();
         }

      I get an error:
      types data.B and data.A are incompatible; both define getIt(), but with unrelated return types


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a file ComplexHierarchy.java with the following contents:
      =====
      package data;

      public class ComplexHierarchy {
          public interface A {
              A getIt();
          }

          public interface B {
              B getIt();
          }

          public interface C extends A, B {
              @Override
              C getIt();
          }

      }
      ====

      Try to compile. Get the error

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No error should be reported (according to my understanding of the JLS)
      ACTUAL -
      Error:
      types data.B and data.A are incompatible; both define getIt(), but with unrelated return types

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      types data.B and data.A are incompatible; both define getIt(), but with unrelated return types


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package data;

      public class ComplexHierarchy {
          public interface A {
              A getIt();
          }

          public interface B {
              B getIt();
          }

          public interface C extends A, B {
              @Override
              C getIt();
          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use ecj

            sadayapalam Srikanth Adayapalam (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: