8000 Bump to dotnet/java-interop/main@5852e6e3 by jonpryor · Pull Request #9931 · dotnet/android · GitHub
[go: up one dir, main page]

Skip to content

Conversation

jonpryor
Copy link
Contributor
@jonpryor jonpryor commented Mar 19, 2025

@jonpryor
Copy link
Contributor 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
@github-actions github-actions bot locked and limited conversation to collaborators Apr 20, 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.

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

1 participant

0