Skip to content
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

Bump to dotnet/java-interop/main@5852e6e3 #9931

Merged
merged 3 commits into from
Mar 20, 2025
Merged

Conversation

jonpryor
Copy link
Member

@jonpryor jonpryor commented Mar 19, 2025

@jonpryor
Copy link
Member Author

…and it crashes! Mono.Android.NET_Tests-Debug has logcat-Debug-Mono.Android.NET_Tests.txt with a crash of:

F mono-rt : [ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.ClassNotFoundException: Didn't find class "crc641855b07eca6dcc03.MyCb" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system/product/lib64, /system/lib64, /system/product/lib64]]
F mono-rt :    at Java.Interop.JniEnvironment.Types.TryFindClass(String classname, Boolean throwOnError)
F mono-rt :    at Java.Interop.JniEnvironment.Types.FindClass(String classname)
F mono-rt :    at Java.Interop.JniType..ctor(String classname)
F mono-rt :    at Java.Interop.JniPeerMembers.JniInstanceMethods..ctor(Type declaringType)
F mono-rt :    at Java.Interop.JniPeerMembers.JniInstanceMethods.GetConstructorsForType(Type declaringType)
F mono-rt :    at Java.Interop.JniPeerMembers.JniInstanceMethods.StartCreateInstance(String constructorSignature, Type declaringType, JniArgumentValue* parameters)
F mono-rt :    at Java.Lang.Object..ctor()
F mono-rt :    at Java.InteropTests.MyCb..ctor()
F mono-rt :    at Java.InteropTests.JnienvTest.<>c__DisplayClass29_0.<DoNotLeakWeakReferences>b__1()
F mono-rt :    at System.Threading.Thread.StartHelper.Callback(Object state)
F mono-rt :    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
F mono-rt : --- End of stack trace from previous location ---
F mono-rt :    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
F mono-rt :   --- End of managed Java.Lang.ClassNotFoundException stack trace ---
F mono-rt : java.lang.ClassNotFoundException: Didn't find class "crc641855b07eca6dcc03.MyCb" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system/product/lib64, /system/lib64, /system/product/lib64]]
F mono-rt :      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
F mono-rt :      at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
F mono-rt :      at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

This will hopefully fix the `Java.Lang.ClassNotFoundException`
that was seen in the previous commit.
jonpryor added a commit to dotnet/java-interop that referenced this pull request Mar 19, 2025
Context: dotnet/android#9931
Context: dotnet/android#9931 (comment)

The attempted integration test crashed!

	F mono-rt : [ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.ClassNotFoundException: Didn't find class "crc641855b07eca6dcc03.MyCb" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system/product/lib64, /system/lib64, /system/product/lib64]]
	F mono-rt :    at Java.Interop.JniEnvironment.Types.TryFindClass(String classname, Boolean throwOnError)
	F mono-rt :    at Java.Interop.JniEnvironment.Types.FindClass(String classname)
	F mono-rt :    at Java.Interop.JniType..ctor(String classname)
	F mono-rt :    at Java.Interop.JniPeerMembers.JniInstanceMethods..ctor(Type declaringType)
	F mono-rt :    at Java.Interop.JniPeerMembers.JniInstanceMethods.GetConstructorsForType(Type declaringType)
	F mono-rt :    at Java.Interop.JniPeerMembers.JniInstanceMethods.StartCreateInstance(String constructorSignature, Type declaringType, JniArgumentValue* parameters)
	F mono-rt :    at Java.Lang.Object..ctor()
	F mono-rt :    at Java.InteropTests.MyCb..ctor()
	F mono-rt :    at Java.InteropTests.JnienvTest.<>c__DisplayClass29_0.<DoNotLeakWeakReferences>b__1()
	F mono-rt :    at System.Threading.Thread.StartHelper.Callback(Object state)
	F mono-rt :    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
	F mono-rt : --- End of stack trace from previous location ---
	F mono-rt :    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
	F mono-rt :   --- End of managed Java.Lang.ClassNotFoundException stack trace ---
	F mono-rt : java.lang.ClassNotFoundException: Didn't find class "crc641855b07eca6dcc03.MyCb" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system/product/lib64, /system/lib64, /system/product/lib64]]
	F mono-rt :      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
	F mono-rt :      at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
	F mono-rt :      at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

Perhaps unsurprisingly, we need to provide the system ClassLoader
in order to load types from outside the default "classpath", which is
why we used `ClassLoader.loadClass()` in the first place.

Instead of `Class.forName()`, use the
[`Class.forName(String name, boolean initialize, ClassLoader loader)`][0]
overload, so that we can provide a `ClassLoader` instance.

This *should* fix the crash.

[0]: https://developer.android.com/reference/java/lang/Class#forName(java.lang.String,%20boolean,%20java.lang.ClassLoader)
@jonpryor jonpryor changed the title Try dotnet/java-interop#1326 Bump to dotnet/java-interop/main@5852e6e3 Mar 20, 2025
@jonpryor jonpryor marked this pull request as ready for review March 20, 2025 16:31
@jonpryor jonpryor merged commit 18ca528 into main Mar 20, 2025
58 checks passed
@jonpryor jonpryor deleted the dev/jonp/jonp-try-ji-1326 branch March 20, 2025 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch JniEnvironment.FindClass to use Class.forName instead of ClassLoader.loadClass
1 participant