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

Incompatible static wildcard bounds

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Fix
    • P3
    • None
    • 8u51, 8u60
    • tools
    • x86_64
    • linux_ubuntu

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_51"
      Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      Attached example compiles with source 1.7, but not with source 1.8.
      I don't know if it is legal according to JLS 1.7 or JLS 1.8. It seems however, that it should be.

      Code compiles when wildcard
      Interval<?> interval = (Interval<?>) object;
      is replaced by raw
      Interval interval = (Interval) object;

      I'm aware that isValid could and should be instance method, Validator could be generic class and so on - but let's ignore that.

      REGRESSION. Last worked in version 8u51


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      IntervalValidator.java:8: error: method isValid in class Interval<C#2> cannot be applied to given types;
                              if (!Interval.isValid(interval)) {
                                           ^
        required: Interval<C#1>
        found: Interval<CAP#1>
        reason: inference variable C#1 has incompatible bounds
          equality constraints: CAP#1
          upper bounds: Comparable<? super C#1>
        where C#1,C#2 are type-variables:
          C#1 extends Comparable<? super C#1> declared in method <C#1>isValid(Interval<C#1>)
          C#2 extends Comparable<? super C#2> declared in class Interval
        where CAP#1 is a fresh type-variable:
          CAP#1 extends Comparable<? super CAP#1> from capture of ?


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      // Interval.java

      public class Interval<C extends Comparable<? super C>> {
      public C lower;
      public C upper;

      public static <C extends Comparable<? super C>> boolean isValid(Interval<C> interval) {
      return interval.lower.compareTo(interval.upper) <= 0;
      }
      }

      // IntervalValidator.java

      public class IntervalValidator implements Validator {
      @Override
      public void validate(Object object) {
      if (object instanceof Interval) {
      Interval<?> interval = (Interval<?>) object;
      if (!Interval.isValid(interval)) {
      throw new RuntimeException();
      }
      }
      }
      }

      // Validator.java

      public interface Validator {
      void validate(Object object);
      }

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

      Attachments

        1. Interval.java
          0.2 kB
        2. IntervalValidator.java
          0.3 kB
        3. Validator.java
          0.1 kB

        Issue Links

          Activity

            People

              dlsmith Dan Smith
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: