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

Failure to detect malformed parameterized type

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 7u51, 8u60, 9
    • Fix Version/s: tbd_major
    • Component/s: tools
    • Labels:

      Description

      The following program compiles without error. An error is expected.

      public class Test {
          interface I<T extends Class<S>, S> {}
          
          <T extends Class<?>> void test() {
              I<T,?> val;
          }
      }

      Specifically, the type 'I<T,?>' is malformed, and so should produce an error (JLS 4.5).

      "When subjected to capture conversion"
      --> 'I<T,CAP>'
      "each type argument Xi is a subtype of" its bound
      --> T <: Class<CAP>

      Because T has upper bound Class<?>, it is not a subtype of Class<CAP> -- in fact, there exists no type Foo such that T <: Class<Foo>.

      (Some aspects of type variables with wildcard-parameterized bounds are under-specified, but in this case, the definition of subtyping is clear.)

      This appears to be longstanding behavior, probably since Java SE 5.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                dlsmith Dan Smith
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: