-
Bug
-
Resolution: Unresolved
-
P4
-
19, 20, 21
-
In Review
-
generic
-
generic
The current implementation of javax.lang.model.Elements.overrides does not take into account the return type of the method.
JavacElements.java
@DefinedBy(Api.LANGUAGE_MODEL)
public boolean overrides(ExecutableElement riderEl,
ExecutableElement rideeEl, TypeElement typeEl) {
MethodSymbol rider = cast(MethodSymbol.class, riderEl);
MethodSymbol ridee = cast(MethodSymbol.class, rideeEl);
ClassSymbol origin = cast(ClassSymbol.class, typeEl);
return rider.name == ridee.name &&
// not reflexive as per JLS
rider != ridee &&
// we don't care if ridee is static, though that wouldn't
// compile
!rider.isStatic() &&
// Symbol.overrides assumes the following
ridee.isMemberOf(origin, types) &&
// check access and signatures; don't check return types
rider.overrides(ridee, origin, types, false);
}
This seems to be working as designed by the last comment if that is the case then is it possible to implement another convenience method which does take into account the return type as in Symbol.java.
JavacElements.java
@DefinedBy(Api.LANGUAGE_MODEL)
public boolean overrides(ExecutableElement riderEl,
ExecutableElement rideeEl, TypeElement typeEl) {
MethodSymbol rider = cast(MethodSymbol.class, riderEl);
MethodSymbol ridee = cast(MethodSymbol.class, rideeEl);
ClassSymbol origin = cast(ClassSymbol.class, typeEl);
return rider.name == ridee.name &&
// not reflexive as per JLS
rider != ridee &&
// we don't care if ridee is static, though that wouldn't
// compile
!rider.isStatic() &&
// Symbol.overrides assumes the following
ridee.isMemberOf(origin, types) &&
// check access and signatures; don't check return types
rider.overrides(ridee, origin, types, false);
}
This seems to be working as designed by the last comment if that is the case then is it possible to implement another convenience method which does take into account the return type as in Symbol.java.
- relates to
-
JDK-8174839 javadoc crashes with a method which does not override a super.
-
- Closed
-
- links to
-
Review(master) openjdk/jdk/22244
-
Review(master) openjdk/jdk/22920