Commit 79c5239
authored
[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.1 parent d062181 commit 79c5239
File tree
7 files changed
+216
-31
lines changed- packages/pigeon
- lib/src
- kotlin
- platform_tests/test_plugin/android/src
- main/kotlin/com/example/test_plugin
- test/kotlin/com/example/test_plugin
7 files changed
+216
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1031 | 1031 | | |
1032 | 1032 | | |
1033 | 1033 | | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
1034 | 1043 | | |
1035 | 1044 | | |
1036 | 1045 | | |
| |||
1043 | 1052 | | |
1044 | 1053 | | |
1045 | 1054 | | |
1046 | | - | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
1047 | 1060 | | |
1048 | 1061 | | |
1049 | 1062 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
47 | 75 | | |
48 | 76 | | |
49 | | - | |
| 77 | + | |
50 | 78 | | |
51 | 79 | | |
52 | 80 | | |
| |||
112 | 140 | | |
113 | 141 | | |
114 | 142 | | |
115 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
116 | 147 | | |
117 | | - | |
| 148 | + | |
118 | 149 | | |
119 | 150 | | |
120 | 151 | | |
| |||
151 | 182 | | |
152 | 183 | | |
153 | 184 | | |
154 | | - | |
| 185 | + | |
155 | 186 | | |
156 | 187 | | |
157 | 188 | | |
158 | 189 | | |
159 | 190 | | |
160 | 191 | | |
161 | | - | |
| 192 | + | |
162 | 193 | | |
163 | 194 | | |
164 | 195 | | |
| |||
199 | 230 | | |
200 | 231 | | |
201 | 232 | | |
202 | | - | |
203 | | - | |
| 233 | + | |
| 234 | + | |
204 | 235 | | |
205 | 236 | | |
206 | 237 | | |
| |||
216 | 247 | | |
217 | 248 | | |
218 | 249 | | |
219 | | - | |
220 | | - | |
| 250 | + | |
| 251 | + | |
221 | 252 | | |
222 | 253 | | |
223 | 254 | | |
| |||
Lines changed: 68 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
79 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
80 | 108 | | |
81 | 109 | | |
82 | | - | |
| 110 | + | |
83 | 111 | | |
84 | 112 | | |
85 | 113 | | |
| |||
144 | 172 | | |
145 | 173 | | |
146 | 174 | | |
147 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
148 | 179 | | |
149 | | - | |
| 180 | + | |
150 | 181 | | |
151 | 182 | | |
152 | 183 | | |
| |||
185 | 216 | | |
186 | 217 | | |
187 | 218 | | |
188 | | - | |
| 219 | + | |
189 | 220 | | |
190 | 221 | | |
191 | 222 | | |
192 | 223 | | |
193 | 224 | | |
194 | 225 | | |
195 | | - | |
| 226 | + | |
196 | 227 | | |
197 | 228 | | |
198 | 229 | | |
| |||
233 | 264 | | |
234 | 265 | | |
235 | 266 | | |
236 | | - | |
237 | | - | |
238 | | - | |
| 267 | + | |
| 268 | + | |
239 | 269 | | |
240 | 270 | | |
241 | 271 | | |
| |||
251 | 281 | | |
252 | 282 | | |
253 | 283 | | |
254 | | - | |
255 | | - | |
| 284 | + | |
| 285 | + | |
256 | 286 | | |
257 | 287 | | |
258 | 288 | | |
| |||
460 | 490 | | |
461 | 491 | | |
462 | 492 | | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
463 | 499 | | |
464 | | - | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
465 | 505 | | |
466 | | - | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
467 | 511 | | |
468 | | - | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
469 | 517 | | |
470 | | - | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
471 | 523 | | |
472 | 524 | | |
473 | 525 | | |
| |||
Lines changed: 87 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
152 | 237 | | |
153 | 238 | | |
154 | 239 | | |
155 | 240 | | |
156 | 241 | | |
157 | 242 | | |
| 243 | + | |
| 244 | + | |
158 | 245 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
0 commit comments