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

Inner classes of type parameters emitted as raw types in signatures

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 21, 25
    • tools
    • None
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      The test method fails to compile, as javac believes that getter.get() returns just Object:

      class Scratch {
          static abstract class Getters<T> {
              abstract class Getter {
                  abstract T get();
              }
          }

          static class Usage<T, G extends Getters<T>> {
              public T test(G.Getter getter) {
                  return getter.get();
              }
          }
      }


      FREQUENCY : always

      If we merely address the issue in allparams() (as in the new backed-off 8343580), the test method compiles, but the emitted signature is as if it was T test(Scratch.Getters.Getter getter), where the Getter inner class appears as a raw type.

      For the attached test on 25 mainline JDK as of 2025 May 23, this fails compilation with such a message:

      TypeVarInners.java:11: error: incompatible types: TypeVarInners.Base cannot be converted to S
      return handler.owner();
      ^
        where S is a type-variable:
          S extends TypeVarInners.Base<S> declared in method <S>getOwner(TypeVarInners.Base.Handler)
      1 error
      error: compilation failed

      Note the method's signature is already wrong in the error message: it should be <S>getOwner(S.Handler)

      Note that assembleClassSig independently examines outer to detect whether it is raw or not:

      if (outer.allparams().nonEmpty()) {
         // rawOuter detection
         // code that emits generic encl type signature
      } else {
         append(externalize(c.flatname));
      }

            Unassigned Unassigned
            liach Chen Liang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: