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

Generics regression on cast

XMLWordPrintable

    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      javac 1.6.0_01

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      javac 1.6 complains of incomparable types when trying to compile
      Main.java but javac 1.5 does not. This sounds like a regression
      since the types do seem comparable.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to compile the attached code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No compilation error.
      ACTUAL -
      javac complains of incomparable types in Main.java

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Main.java:7: incomparable types: bugs.case02.Token<bugs.case02.Foo.Tag,bugs.case02.Foo> and bugs.case02.Token<capture#636 of ?,capture#203 of ? extends bugs.case02.Entity<capture#636 of ?>>
              boolean z1 = Token.FOO == x.getToken();
                                     ^
      1 error


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      package bugs;

      public interface Entity<T extends Entity.Tag<?>> {

          public EntityToken<T, ? extends Entity<T>> getToken();

          public static interface Tag<E extends Entity<?>> {

              public EntityToken<? extends Tag<E>, E> getToken();
          }
      }

      package bugs;

      public class Glycan implements Entity<Glycan.Tag> {

          public EntityToken<Glycan.Tag, Glycan> getToken() {
              return EntityToken.GLYCAN;
          }

          public static class Tag implements Entity.Tag<Glycan> {

              public EntityToken<Glycan.Tag, Glycan> getToken() {
                  return EntityToken.GLYCAN;
              }
          }
      }

      package bugs;

      public class EntityToken<T extends Entity.Tag<?>, E extends Entity<?>> {

          private EntityToken() { }

          public static final EntityToken<Glycan.Tag, Glycan> GLYCAN =
              new EntityToken<Glycan.Tag, Glycan>();
      }

      package bugs;

      public class Main2 {

          public static <E extends Entity<?>> E transform(E x) {
              return x.getToken() == EntityToken.GLYCAN ? x : null;
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      See the Main.java source.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: