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));
}
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));
}
- relates to
-
JDK-8343580 Type error with inner classes of generic classes in functions generic by outer
-
- Resolved
-