Skip to content

AndroidComponentAddress hashCode() isn't consistent with equals() on SDK >= 31 #9045

Closed
@jdcormie

Description

@jdcormie

Steps to reproduce the bug

AndroidComponentAddress one = AndroidComponentAddress.forBindIntent(new Intent()
  .setComponent("package", "service")
);
AndroidComponentAddress two = AndroidComponentAddress.forBindIntent(new Intent()
  .setComponent("package", "service")
  .setPackage("package")
);

assert(!one.equals(two) || (one.hashCode() == two.hashCode()))

What did you expect to see?

No assertion error. The Object API contract says that if one.equals(two) then one.hashCode() == two.hashCode().

What did you see instead?

Assertion error because, since Android SDK 31, one.equals(two) but one.hashCode() != two.hashCode().

AndroidComponentAddress implements hashCode() and equals() by delegating to Intent.filterHashcode() and filterEquals(). But since https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/9324284 filterHashcode() and filterEquals() are no longer consistent the way Object requires when a (redundant) setPackage() filter is present.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions