Skip to content

Commit c5062a6

Browse files
[Tests] Re-enable 7 trimmable typemap tests
Add trimmable-typemap variant of GetThis.java that uses mono.android.Runtime.register instead of ManagedPeer.registerNativeMembers. Java.Interop-Tests.targets swaps variants based on $(_AndroidTypeMapImplementation). Re-enabled tests: - JavaCast_BadInterfaceCast (bad-cast disambiguation) - JavaCast_BaseToGenericWrapper (closed-generic activation) - JavaCast_CheckForManagedSubclasses (bad-cast disambiguation) - JavaCast_InvalidTypeCastThrows (bad-cast disambiguation) - JavaAs_Exceptions (inherited ctor fix) - DisposeAccessesThis (trimmable GetThis.java) - CreateGenericValue (ArrayRank scanner fix) Updated remaining exclusion comments with accurate root-cause descriptions. Removed resolved TODO comments from test files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a804994 commit c5062a6

4 files changed

Lines changed: 90 additions & 27 deletions

File tree

tests/Mono.Android-Tests/Java.Interop-Tests/Java.Interop-Tests.targets

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,40 @@
1010
</TestJarEntry>
1111
</ItemDefinitionGroup>
1212
<ItemGroup>
13-
<TestJarEntry Include="$(MSBuildThisFileDirectory)..\..\..\external\Java.Interop\tests\Java.Interop-Tests\java\**\*.java" />
13+
<!--
14+
java-trimmable/net/dot/jni/test/GetThis.java is added explicitly via
15+
TestJarEntry below when building for the trimmable typemap; it must be
16+
removed from the implicit AndroidJavaSource glob so the .NET SDK does
17+
not also try to compile it as a regular AndroidJavaSource (which would
18+
collide with the desktop GetThis.java in the test JAR).
19+
-->
20+
<AndroidJavaSource Remove="java-trimmable\**\*.java" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<!--
25+
java-trimmable/net/dot/jni/test/GetThis.java is the Android trimmable
26+
typemap variant of the Java.Interop GetThis.java test fixture. It omits
27+
the desktop-JVM static initializer (net.dot.jni.ManagedPeer.registerNativeMembers /
28+
ManagedPeer.construct) that is only registered by the Java.Interop test
29+
JVM and throws UnsatisfiedLinkError on Android. Both files declare
30+
`public class net.dot.jni.test.GetThis`, so include exactly one based on
31+
$(_AndroidTypeMapImplementation). The trimmable variant lives in this
32+
project (not the submodule) and in a parallel directory because javac
33+
requires the file name match the public class name.
34+
-->
35+
<!--
36+
Both branches below are mutually exclusive on $(_AndroidTypeMapImplementation).
37+
Switching between trimmable and non-trimmable requires a clean rebuild because
38+
MSBuild's up-to-date check doesn't track the conditional swap automatically.
39+
-->
40+
<TestJarEntry Include="$(MSBuildThisFileDirectory)..\..\..\external\Java.Interop\tests\Java.Interop-Tests\java\**\*.java"
41+
Exclude="$(MSBuildThisFileDirectory)..\..\..\external\Java.Interop\tests\Java.Interop-Tests\java\net\dot\jni\test\GetThis.java"
42+
Condition=" '$(_AndroidTypeMapImplementation)' == 'trimmable' " />
43+
<TestJarEntry Include="$(MSBuildThisFileDirectory)..\..\..\external\Java.Interop\tests\Java.Interop-Tests\java\**\*.java"
44+
Condition=" '$(_AndroidTypeMapImplementation)' != 'trimmable' " />
45+
<TestJarEntry Include="$(MSBuildThisFileDirectory)java-trimmable\net\dot\jni\test\GetThis.java"
46+
Condition=" '$(_AndroidTypeMapImplementation)' == 'trimmable' " />
1447
</ItemGroup>
1548
<Target Name="_CopyTestJarFiles">
1649
<Copy
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package net.dot.jni.test;
2+
3+
import java.util.ArrayList;
4+
5+
import net.dot.jni.GCUserPeerable;
6+
7+
// Variant of GetThis used by the Mono.Android.NET-Tests trimmable typemap lane.
8+
//
9+
// The desktop-JVM variant (../../../java/net/dot/jni/test/GetThis.java) relies
10+
// on net.dot.jni.ManagedPeer.registerNativeMembers / ManagedPeer.construct;
11+
// those native methods are only registered by the Java.Interop test JVM and
12+
// throw UnsatisfiedLinkError on Android, which makes the static initializer
13+
// here fail when the class is loaded on a real device.
14+
//
15+
// Under the Android trimmable typemap, the C# `GetThis : JavaObject` peer is
16+
// constructed via the standard Java.Interop / Mono.Android peer construction
17+
// path, so the Java class only needs:
18+
// - getThis() — exercised by JavaObjectTest.DisposeAccessesThis
19+
// - GCUserPeerable implementation so the runtime registers managed-side
20+
// references (see Android.Runtime.JNIEnv.IsGCUserPeer)
21+
public class GetThis implements GCUserPeerable {
22+
23+
ArrayList<Object> managedReferences = new ArrayList<Object>();
24+
25+
public GetThis () {
26+
}
27+
28+
public final GetThis getThis () {
29+
return this;
30+
}
31+
32+
public void jiAddManagedReference (java.lang.Object obj)
33+
{
34+
managedReferences.add (obj);
35+
}
36+
37+
public void jiClearManagedReferences ()
38+
{
39+
managedReferences.clear ();
40+
}
41+
}

tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JavaObjectExtensionsTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace Java.InteropTests {
1515
[TestFixture]
1616
public class JavaObjectExtensionsTests {
1717

18-
// TODO: https://github.com/dotnet/android/issues/11170 — cannot create instance of open generic type under trimmable typemap
1918
[Test]
2019
public void JavaCast_BaseToGenericWrapper ()
2120
{
@@ -42,7 +41,6 @@ public void JavaCast_InterfaceCast ()
4241
}
4342
}
4443

45-
// TODO: https://github.com/dotnet/android/issues/11170 — throws NotSupportedException instead of InvalidCastException under trimmable typemap
4644
[Test]
4745
public void JavaCast_BadInterfaceCast ()
4846
{
@@ -69,7 +67,6 @@ public void JavaCast_ObtainOriginalInstance ()
6967
Assert.AreSame (list, al);
7068
}
7169

72-
// TODO: https://github.com/dotnet/android/issues/11170 — throws NotSupportedException instead of InvalidCastException under trimmable typemap
7370
[Test]
7471
public void JavaCast_InvalidTypeCastThrows ()
7572
{
@@ -78,7 +75,6 @@ public void JavaCast_InvalidTypeCastThrows ()
7875
}
7976
}
8077

81-
// TODO: https://github.com/dotnet/android/issues/11170 — throws NotSupportedException instead of InvalidCastException under trimmable typemap
8278
[Test]
8379
public void JavaCast_CheckForManagedSubclasses ()
8480
{

tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.RuntimeTests/NUnitInstrumentation.cs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@ protected NUnitInstrumentation(IntPtr handle, JniHandleOwnership transfer)
3434
// net.dot.jni.test.CallVirtualFromConstructorDerived Java class not in APK
3535
"Java.InteropTests.InvokeVirtualFromConstructorTests",
3636

37-
// net.dot.jni.internal.JavaProxyObject Java class not in APK — fixture setup fails (16 tests)
37+
// net.dot.jni.internal.JavaProxyObject.<clinit> calls
38+
// net.dot.jni.ManagedPeer.registerNativeMembers, which the trimmable
39+
// typemap path rejects (Native methods must be registered by JCW
40+
// static initializer blocks). Fixing this requires a parallel
41+
// Android-trimmable variant of JavaProxyObject.java that registers
42+
// its native equals/hashCode/toString via mono.android.Runtime.register
43+
// — an architectural change tracked separately from the JavaCast / JavaAs
44+
// work in this PR. See https://github.com/dotnet/android/issues/11170.
3845
"Java.InteropTests.JavaObjectArray_object_ContractTest",
3946

40-
// net.dot.jni.internal.JavaProxyObject Java class not in APK
47+
// Same root cause as above (JavaProxyObject static init).
4148
"Java.InteropTests.JniValueMarshaler_object_ContractTests.JniValueMarshalerContractTests`1.CreateArgumentState",
4249
"Java.InteropTests.JniValueMarshaler_object_ContractTests.JniValueMarshalerContractTests`1.CreateGenericArgumentState",
4350
"Java.InteropTests.JniValueMarshaler_object_ContractTests.JniValueMarshalerContractTests`1.CreateGenericObjectReferenceArgumentState",
@@ -46,18 +53,10 @@ protected NUnitInstrumentation(IntPtr handle, JniHandleOwnership transfer)
4653
"Java.InteropTests.JniValueMarshaler_object_ContractTests.JniValueMarshalerContractTests`1.CreateValue",
4754
"Java.InteropTests.JniValueMarshaler_object_ContractTests.SpecificTypesAreUsed",
4855

49-
// No generated JavaPeerProxy for java/lang/Object with IJavaPeerable target type
50-
"Java.InteropTests.JniValueMarshaler_IJavaPeerable_ContractTests.JniValueMarshalerContractTests`1.CreateGenericValue",
51-
"Java.InteropTests.JniValueMarshaler_IJavaPeerable_ContractTests.JniValueMarshalerContractTests`1.CreateValue",
52-
53-
// net.dot.jni.internal.JavaProxyThrowable — proxy throwable creation fails
56+
// net.dot.jni.internal.JavaProxyThrowable static init — same JavaProxy*
57+
// root cause as the JavaProxyObject exclusions above.
5458
"Java.InteropTests.JavaExceptionTests.InnerExceptionIsNotAProxy",
5559

56-
// IJavaInterfaceInvoker ctor trimmed / missing JavaPeerProxy for test types
57-
"Java.InteropTests.JavaPeerableExtensionsTests.JavaAs",
58-
"Java.InteropTests.JavaPeerableExtensionsTests.JavaAs_Exceptions",
59-
"Java.InteropTests.JavaPeerableExtensionsTests.JavaAs_InstanceThatDoesNotImplementInterfaceReturnsNull",
60-
6160
// JNI method remapping not supported in trimmable typemap
6261
"Java.InteropTests.JniPeerMembersTests.ReplaceInstanceMethodName",
6362
"Java.InteropTests.JniPeerMembersTests.ReplaceInstanceMethodWithStaticMethod",
@@ -67,18 +66,12 @@ protected NUnitInstrumentation(IntPtr handle, JniHandleOwnership transfer)
6766
// net.dot.jni.test.GenericHolder Java class not in APK
6867
"Java.InteropTests.JniTypeManagerTests.CannotCreateGenericHolderFromJava",
6968

70-
// JniPrimitiveArrayInfo lookup fails for JavaBooleanArray
69+
// JniPrimitiveArrayInfo lookup fails for JavaBooleanArray —
70+
// our typemap returns JavaBooleanArray for "Z" via JavaPrimitiveArray<>
71+
// alias, which collides with the legacy GetPrimitiveArrayTypesForSimpleReference
72+
// that expects only primitive CLR types. Out of scope for this PR.
7173
"Java.InteropTests.JniTypeManagerTests.GetType",
7274

73-
// net.dot.jni.test.GetThis — cannot register native members
74-
"Java.InteropTests.JavaObjectTest.DisposeAccessesThis",
75-
76-
// NotSupportedException instead of InvalidCastException — no generated JavaPeerProxy
77-
"Java.InteropTests.JavaObjectExtensionsTests.JavaCast_BadInterfaceCast",
78-
"Java.InteropTests.JavaObjectExtensionsTests.JavaCast_BaseToGenericWrapper",
79-
"Java.InteropTests.JavaObjectExtensionsTests.JavaCast_CheckForManagedSubclasses",
80-
"Java.InteropTests.JavaObjectExtensionsTests.JavaCast_InvalidTypeCastThrows",
81-
8275
// Open generic type handling differs from non-trimmable
8376
"Java.InteropTests.JnienvTest.NewOpenGenericTypeThrows",
8477

0 commit comments

Comments
 (0)