Commit 6096f8b
authored
[tests] fix trimmer warnings in Java.Interop-Tests (#1318)
Context: dotnet/android#9846
When building `Mono.Android.NET-Tests.csproj` for NativeAOT, you end
up with many warnings (that are upgraded to errors):
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniEnvironmentTests.cs(92,4): error IL2026: Using member 'System.Reflection.Assembly.GetType(String, Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed by trimming. If the type name is a string literal, consider using Type.GetType instead.
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniEnvironmentTests.cs(93,4): error IL2026: Using member 'System.Reflection.Assembly.GetType(String, Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed by trimming. If the type name is a string literal, consider using Type.GetType instead.
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JavaObjectArrayTest.cs(15,11): error IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in 'Java.Interop.JavaObjectArray<T>'. The generic parameter 'T' of 'Java.InteropTests.JavaObjectArrayContractTest<T>' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JavaObjectArrayTest.cs(21,48): error IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in 'Java.Interop.JavaObjectArray<T>'. The generic parameter 'T' of 'Java.InteropTests.JavaObjectArrayContractTest<T>' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JavaObjectArrayTest.cs(22,48): error IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in 'Java.Interop.JavaObjectArray<T>'. The generic parameter 'T' of 'Java.InteropTests.JavaObjectArrayContractTest<T>' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JavaObjectArrayTest.cs(23,44): error IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in 'Java.Interop.JavaObjectArray<T>'. The generic parameter 'T' of 'Java.InteropTests.JavaObjectArrayContractTest<T>' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JavaExceptionTests.cs(105,34): error IL2026: Using member 'System.Reflection.Assembly.GetType(String, Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed by trimming. If the type name is a string literal, consider using Type.GetType instead.
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JavaExceptionTests.cs(108,34): error IL2072: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Activator.CreateInstance(Type, params Object[])'. The return value of method 'System.Reflection.Assembly.GetType(String, Boolean)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniEnvironmentTests.cs(99,41): error IL2077: 'target' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Delegate.CreateDelegate(Type, Type, String, Boolean, Boolean)'. The field 'Java.InteropTests.JniEnvironmentTests.NativeMethods_type' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniEnvironmentTests.cs(111,35): error IL2077: 'target' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Delegate.CreateDelegate(Type, Type, String, Boolean, Boolean)'. The field 'Java.InteropTests.JniEnvironmentTests.NativeMethods_type' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniValueMarshalerContractTests.cs(650,127): error IL2092: 'DynamicallyAccessedMemberTypes' in 'DynamicallyAccessedMembersAttribute' on the parameter 'targetType' of method 'Java.InteropTests.DemoValueTypeValueMarshaler.CreateGenericValue(ref JniObjectReference, JniObjectReferenceOptions, Type)' don't match overridden parameter 'targetType' of method 'Java.Interop.JniValueMarshaler<T>.CreateGenericValue(ref JniObjectReference, JniObjectReferenceOptions, Type)'. All overridden members must have the same 'DynamicallyAccessedMembersAttribute' usage.
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniRuntimeJniValueManagerContract.cs(28,18): error IL2072: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'Java.InteropTests.JniRuntimeJniValueManagerContract.ValueManagerType.get' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniValueMarshalerContractTests.cs(36,35): error IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in 'Java.Interop.JniRuntime.JniValueManager.GetValueMarshaler<T>()'. The generic parameter 'T' of 'Java.InteropTests.JniValueMarshalerContractTests<T>' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniValueMarshalerContractTests.cs(224,18): error IL2026: Using member 'Java.Interop.JniValueMarshaler.CreateReturnValueFromManagedExpression(JniValueMarshalerContext, ParameterExpression)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. System.Linq.Expression usage may trim away required code.
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniValueMarshalerContractTests.cs(224,18): error IL3050: Using member 'Java.Interop.JniValueMarshaler.CreateReturnValueFromManagedExpression(JniValueMarshalerContext, ParameterExpression)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. System.Linq.Expression usage may trim away required code.
We can address these here by importing:
<Import Project="..\..\build-tools\trim-analyzers\trim-analyzers.props" />
And then solving the warnings (that are now errors) by adding missing
attributes.
This might also improve the chances of these tests passing under
NativeAOT, in general.1 parent 719e615 commit 6096f8b
File tree
6 files changed
+44
-13
lines changed- tests/Java.Interop-Tests
- Java.Interop
6 files changed
+44
-13
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 | | |
| |||
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
106 | | - | |
107 | | - | |
| 105 | + | |
108 | 106 | | |
109 | 107 | | |
110 | 108 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| 92 | + | |
91 | 93 | | |
92 | | - | |
93 | | - | |
| 94 | + | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| |||
Lines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
296 | 298 | | |
297 | 299 | | |
298 | 300 | | |
299 | | - | |
300 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
301 | 307 | | |
302 | 308 | | |
303 | 309 | | |
| |||
313 | 319 | | |
314 | 320 | | |
315 | 321 | | |
| 322 | + | |
316 | 323 | | |
317 | 324 | | |
| 325 | + | |
318 | 326 | | |
319 | 327 | | |
320 | 328 | | |
| |||
Lines changed: 23 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
17 | 22 | | |
18 | 23 | | |
19 | 24 | | |
| |||
211 | 216 | | |
212 | 217 | | |
213 | 218 | | |
| 219 | + | |
| 220 | + | |
214 | 221 | | |
215 | 222 | | |
216 | 223 | | |
| |||
335 | 342 | | |
336 | 343 | | |
337 | 344 | | |
338 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
339 | 350 | | |
340 | 351 | | |
341 | 352 | | |
| |||
442 | 453 | | |
443 | 454 | | |
444 | 455 | | |
445 | | - | |
446 | | - | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
447 | 461 | | |
448 | 462 | | |
449 | 463 | | |
| |||
647 | 661 | | |
648 | 662 | | |
649 | 663 | | |
650 | | - | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
651 | 669 | | |
652 | 670 | | |
653 | 671 | | |
| |||
0 commit comments