Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jdcormie opened this issue Apr 1, 2022 · 1 comment · Fixed by #9061
Closed

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

jdcormie opened this issue Apr 1, 2022 · 1 comment · Fixed by #9061
Labels
Milestone

Comments

@jdcormie
Copy link
Member

jdcormie commented Apr 1, 2022

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.

@sergiitk sergiitk added the bug label Apr 5, 2022
@sergiitk
Copy link
Member

sergiitk commented Apr 5, 2022

@jdcormie do you have someone specific in mind to assign this bug to?

@sergiitk sergiitk added this to the Next milestone Apr 5, 2022
jdcormie added a commit that referenced this issue Apr 6, 2022
Where filterEquals() can be inconsistent with filterHashCode().

Fixes #9045
@sergiitk sergiitk modified the milestones: Next, v1.46 Apr 6, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants