Fix NPE on equals/hashCode of local function references
Anonymous classes for local function references implement their getOwner() as "return null" currently (KT-14291). To avoid NPE in this case, we now consider two local functions the same if their name and signature are equal. This is incorrect in general, but unlikely to cause major problems and is going to be fixed by KT-14291 eventually anyway #KT-17055
This commit is contained in:
@@ -86,7 +86,7 @@ public class FunctionReference extends CallableReference implements FunctionBase
|
||||
if (obj instanceof FunctionReference) {
|
||||
FunctionReference other = (FunctionReference) obj;
|
||||
|
||||
return getOwner().equals(other.getOwner()) &&
|
||||
return (getOwner() == null ? other.getOwner() == null : getOwner().equals(other.getOwner())) &&
|
||||
getName().equals(other.getName()) &&
|
||||
getSignature().equals(other.getSignature()) &&
|
||||
Intrinsics.areEqual(getBoundReceiver(), other.getBoundReceiver());
|
||||
@@ -99,7 +99,7 @@ public class FunctionReference extends CallableReference implements FunctionBase
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (getOwner().hashCode() * 31 + getName().hashCode()) * 31 + getSignature().hashCode();
|
||||
return ((getOwner() == null ? 0 : getOwner().hashCode() * 31) + getName().hashCode()) * 31 + getSignature().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user