8374654: Inconsistent handling of lambda deserialization for Object method references on interfaces

This commit is contained in:
Liam Miller-Cushon 2026-01-06 23:04:00 +01:00
parent 629bf20f59
commit e3bb33ed42
2 changed files with 13 additions and 10 deletions

View File

@ -2858,13 +2858,17 @@ public class Types {
hasSameArgs(t, erasure(s)) || hasSameArgs(erasure(t), s);
}
public boolean overridesObjectMethod(TypeSymbol origin, Symbol msym) {
public Symbol overriddenObjectMethod(TypeSymbol origin, Symbol msym) {
for (Symbol sym : syms.objectType.tsym.members().getSymbolsByName(msym.name)) {
if (msym.overrides(sym, origin, Types.this, true)) {
return true;
return sym;
}
}
return false;
return null;
}
public boolean overridesObjectMethod(TypeSymbol origin, Symbol msym) {
return overriddenObjectMethod(origin, msym) != null;
}
/**

View File

@ -702,13 +702,12 @@ public class LambdaToMethod extends TreeTranslator {
String functionalInterfaceClass = classSig(targetType);
String functionalInterfaceMethodName = samSym.getSimpleName().toString();
String functionalInterfaceMethodSignature = typeSig(types.erasure(samSym.type));
Symbol baseMethod = refSym.baseSymbol();
Symbol origMethod = baseMethod.baseSymbol();
if (baseMethod != origMethod && origMethod.owner == syms.objectType.tsym) {
//the implementation method is a java.lang.Object method transferred to an
//interface that does not declare it. Runtime will refer to this method as to
//a java.lang.Object method, so do the same:
refSym = ((MethodSymbol) origMethod).asHandle();
Symbol baseMethod = types.overriddenObjectMethod(refSym.enclClass(), refSym);
if (baseMethod != null) {
// The implementation method is a java.lang.Object method, runtime will resolve this method to
// a java.lang.Object method, so do the same.
// This case can be removed if JDK-8172817 is fixed.
refSym = ((MethodSymbol) baseMethod).asHandle();
}
String implClass = classSig(types.erasure(refSym.owner.type));
String implMethodName = refSym.getQualifiedName().toString();