Commit d62008d
authored
[Java.Interop] GetSimpleReferences(): fallback for GetTypeSignatures() (#1305)
Context: dotnet/android#9768
dotnet/android#9768 attempts to add types from `Java.Interop.dll` to
the .NET for Android typemaps, in order to fix Debug warnings like:
I monodroid-assembly: typemap: unable to find mapping to a Java type from managed type 'Java.Interop.ManagedPeer, Java.Interop'
Unfortunately, the initial attempt to generate typemaps for
`Java.Interop.dll` caused the assertion:
AssertGetJniTypeInfoForType (typeof (JavaArray<JavaObject>), "[Ljava/lang/Object;", false, 1);
within `Java.InteropTests.JniTypeManagerTests.GetTypeSignature_Type()`
to fail with:
Expected string length 19 but was 33. Strings differ at index 0.
Expected: "[Ljava/lang/Object;"
But was: "crc64d5d92128469ae06d/JavaArray_1"
-----------^
The immediate cause of the failure is that
`JniRuntime.JniTypeManager.GetTypeSignature()` called
`JniRuntime.JniTypeManager.GetSimpleReference()` *before* it tried
to see if the type was `JavaArray<T>`. As `Java.Interop.dll` was now
being processed for typemap purposes, and because `JavaArray<T>` did
not have a `[JniTypeSignatureAttribute]`, the typemap got the default
behavior of `crc64[hash…]`.
The broader cause is that `GetSimpleReference()` should be the
*fallback* implementation, used after all other attempts to get a
JNI name have failed.
Update `GetTypeSignature()` and `GetTypeSignatures()` so that
`GetSimpleReference()` and/or `GetSimpleReferences()` are in fact
treated as fallbacks.
Additionally, update `AssertGetJniTypeInfoForType()` to assert that
the value returned by `GetTypeSignature()` is the same as the value
return3ed by` GetTypeSignatures().First()`. This was *commented* as
being the case, but we should *verify* that as well.
Finally, *move* the
`type.GetCustomAttribute<JniTypeSignatureAttribute()` and
`GetReplacementType()` logic into `GetSimpleReferences()`. This
This emphasizes the "fallback" nature of `GetSimpleReference()`,
adds an missing `GetReplacementType()` invocation from the
`GetTypeSignatures()` codepath, and this is what
[`AndroidTypeManager.GetSimpleReference()`][0] was already doing.
[0]: https://github.com/dotnet/android/blob/21c413195e300b6440eb437dade4f3a114e795f7/src/Mono.Android/Android.Runtime/AndroidRuntime.cs#L279-L2891 parent 57f7bc8 commit d62008d
File tree
4 files changed
+48
-43
lines changed- src/Java.Interop/Java.Interop
- tests/Java.Interop-Tests/Java.Interop
4 files changed
+48
-43
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
362 | 363 | | |
363 | 364 | | |
364 | 365 | | |
| 366 | + | |
365 | 367 | | |
366 | 368 | | |
367 | 369 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
Lines changed: 34 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | 159 | | |
175 | 160 | | |
176 | 161 | | |
177 | 162 | | |
178 | 163 | | |
179 | 164 | | |
180 | 165 | | |
181 | | - | |
182 | 166 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
187 | 170 | | |
188 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
189 | 176 | | |
190 | 177 | | |
191 | 178 | | |
| |||
194 | 181 | | |
195 | 182 | | |
196 | 183 | | |
| 184 | + | |
| 185 | + | |
197 | 186 | | |
198 | 187 | | |
199 | 188 | | |
200 | 189 | | |
201 | 190 | | |
202 | | - | |
| 191 | + | |
203 | 192 | | |
204 | 193 | | |
205 | 194 | | |
206 | 195 | | |
207 | 196 | | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
| 197 | + | |
| 198 | + | |
221 | 199 | | |
222 | | - | |
| 200 | + | |
223 | 201 | | |
224 | 202 | | |
225 | 203 | | |
226 | | - | |
227 | 204 | | |
228 | | - | |
229 | | - | |
230 | | - | |
| 205 | + | |
| 206 | + | |
231 | 207 | | |
232 | | - | |
| 208 | + | |
233 | 209 | | |
234 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
235 | 217 | | |
236 | 218 | | |
237 | 219 | | |
| |||
266 | 248 | | |
267 | 249 | | |
268 | 250 | | |
269 | | - | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
270 | 263 | | |
271 | 264 | | |
272 | 265 | | |
| |||
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
82 | 85 | | |
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
88 | 91 | | |
89 | | - | |
90 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
91 | 100 | | |
92 | 101 | | |
93 | 102 | | |
| |||
0 commit comments