Skip to content

[tests] enable Java.Interop-Tests for CoreCLR #10095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2025

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented May 1, 2025

Until a "GC Bridge" exists, for Java.Interop-Tests to work on the new runtimes, we need to set:

<DefineConstants Condition=" '$(UseMonoRuntime)' == 'false' or '$(PublishAot)' == 'true' ">$(DefineConstants);NO_GC_BRIDGE_SUPPORT</DefineConstants>

@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/java.interop-tests branch from 4da4e84 to ed267ff Compare May 1, 2025 23:47
jonathanpeppers added a commit that referenced this pull request May 2, 2025
Context: #10095

After enabling `Java.Interop-Tests.dll` for CoreCLR/NativeAOT, we started seeing
`Java.InteropTests.JavaExceptionTests.InnerExceptionIsNotAProxy()` fail with:

    Expected: same as <System.InvalidOperationException: Managed Exception!>
    But was:  <Java.Interop.JavaProxyThrowable: System.InvalidOperationException: Managed Exception!

This is because `AndroidRuntime.cs` was doing:

    if (JNIEnvInit.ValueManager is AndroidValueManager vm) {
        return vm.UnboxException (value);
    }

And in this case `ManagedValueManager` was being used, and so the
exception would not be "unboxed".

We can fix this by using `JNIEnvInit.ValueManager?.PeekValue()`
instead and the test now passes.

I also noticed that `AndroidValueManager` had code in
`TryUnboxPeerObject()` for:

    var proxy = value as Android.Runtime.JavaProxyThrowable;
    if (proxy != null) {
        result  = proxy.InnerException;
        return true;
    }
    return base.TryUnboxPeerObject (value, out result);

While the base class handled `Java.Interop.JavaProxyThrowable`. This
was missing for `ManagedValueManager`, so I added it.
jonpryor pushed a commit that referenced this pull request May 2, 2025
…0100)

Context: #10095

After enabling `Java.Interop-Tests.dll` for CoreCLR/NativeAOT,
`Java.InteropTests.JavaExceptionTests.InnerExceptionIsNotAProxy()`
was failing with:

	Expected: same as <System.InvalidOperationException: Managed Exception!>
	But was:  <Java.Interop.JavaProxyThrowable: System.InvalidOperationException: Managed Exception!

This is because `AndroidRuntime.cs` was doing:

	if (JNIEnvInit.ValueManager is AndroidValueManager vm) {
	    return vm.UnboxException (value);
	}

And in this case `ManagedValueManager` was being used, and so the
exception would not be "unboxed".

We can fix this by using `JNIEnvInit.ValueManager?.PeekValue()`
instead and the test now passes.

I also noticed that `AndroidValueManager` had code in
`TryUnboxPeerObject()` for:

	var proxy = value as Android.Runtime.JavaProxyThrowable;
	if (proxy != null) {
	    result  = proxy.InnerException;
	    return true;
	}
	return base.TryUnboxPeerObject (value, out result);

While the base class handled `Java.Interop.JavaProxyThrowable`.
This was missing for `ManagedValueManager`, so I added it.
@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/java.interop-tests branch from 0edcba4 to bd46275 Compare May 3, 2025 14:35
@jonathanpeppers jonathanpeppers changed the title [tests] enable Java.Interop-Tests for CoreCLR/NativeAOT [tests] enable Java.Interop-Tests for CoreCLR May 3, 2025
@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/java.interop-tests branch 2 times, most recently from da1f05b to 975ad6a Compare May 6, 2025 02:19
@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/java.interop-tests branch from 975ad6a to b3d6865 Compare May 6, 2025 13:21
@jonathanpeppers jonathanpeppers marked this pull request as ready for review May 6, 2025 13:21
@jonathanpeppers jonathanpeppers requested a review from jonpryor as a code owner May 6, 2025 13:21
Copy link
Contributor

@jpobst jpobst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathanpeppers jonathanpeppers merged commit 9ab2952 into main May 6, 2025
59 checks passed
@jonathanpeppers jonathanpeppers deleted the dev/peppers/java.interop-tests branch May 6, 2025 19:39
@jonathanpeppers jonathanpeppers mentioned this pull request May 7, 2025
8 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Jun 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants