You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[pigeon] Fixes support for Kotlin/Java classes that override equals and hashCode for ProxyApis (#10039)
ProxyApis for classes that override `equals()/hashcode` in Kotlin/Java were breaking the `InstanceManager`.
The Kotlin `InstanceManager` would:
1. Return true for `containsInstance`.
2. Then remove the strong reference to the original object in `getIdentifierForStrongReference`.
3. Erroneously trigger the call to Dart to remove the strong reference of an instance.
This changes the the use of `WeakReference` to a new `IdentityWeakReference` that uses identity to check for equality. Java/Kotlin has an `IdentityHashMap` and a `WeakHashMap`, but not an `IdentityWeakHashMap`. So this is a quick workaround to create an equivalent.
Alternatively, `getIdentifierForStrongReference` could be updated to check `containsInstance` first, but this would leave small timeframes where objects would only have a weak reference. And it seems possible that Kotlin GC could cleanup at any moment.
Potential fix for flutter/flutter#174134 since the class they were creating a ProxyApi for was a data class: https://github.com/JavesonYehudi/proxy_bug_report/blob/main/android/src/main/kotlin/com/example/proxy_bug_report/auth/Credentials.kt
## Pre-Review Checklist
**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Copy file name to clipboardExpand all lines: packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/ProxyApiTests.gen.kt
+68-16Lines changed: 68 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -75,11 +75,39 @@ class ProxyApiTestsPigeonInstanceManager(
Copy file name to clipboardExpand all lines: packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/InstanceManagerTest.kt
0 commit comments