Search Issue Tracker
By Design
By Design in 2023.2.X
Votes
0
Found in
2022.2.9f1
2023.1.0b5
2023.2.0a4
Issue ID
UUM-30598
Regression
Yes
AndroidJNI.FindClass() always returns IntPtr.Zero when called inside class destructor or finalizer
Reproduction steps:
1. Open the attached project "AndroidJNITests"
2. Build And Run on an Android device
3. Press the “Alloc DummyObject” button
4. Press “Collect GC to trigger DummyObject Finalizer”
5. See the returned output of AndroidJNI.FindClass()
Expected result: Returned value is non-zero
Actual result: Returned value is zero
Reproducible with: 2022.2.0a12, 2022.2.9f1, 2023.1.0b5, 2023.2.0a4
Not reproducible with: 2020.3.46f1, 2021.3.20f1, 2022.2.0a11
Reproducible with devices:
VLNQA00332, Samsung Galaxy XCover4 (SM-G390F), Android 9, CPU: Exynos 7 Quad 7570, GPU: Mali-T720
VLNQA00325, Samsung Galaxy Note10 (SM-N970F), Android 12, CPU: NOT FOUND, GPU: Mali-G76
VLNQA00318, Oneplus OnePlus 7 Pro (GM1913), Android 11, CPU: Snapdragon 855 SM8150, GPU: Adreno (TM) 640
VLNQA00231, Samsung Galaxy A5(2017) (SM-A520F), Android 8.0.0, CPU: Exynos 7 Octa 7880, GPU: Mali-T830
VLNQA00231, Huawei HUAWEI Mate 20 Pro (LYA-L29), Android 9, CPU: HiSilicon Kirin 980, GPU: Mali-G76
iPhone 13 Pro (iOS 15.6.1)
Reproducible on: Windows 10 Enterprise 21H2
Notes:
- AndroidJNI.FindClass() method in the object's destructor/finalizer always returns an IntPtr.Zero (note that the Java class exists).
It is expected that this method returns the Java class ID
- This works in any other context but in the object's destructor/finalizer
- This bug occurs on Release and Development build
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Performance Markers Search window shows an empty entry in the list
- Enabling Deep Profiling in Performance Markers Search window breaks Inspector panel buttons when navigating through the marker items
- Dragging selector from selector row background shows preview but does not apply class in UI Builder
- An "InvalidOperationException" error is thrown when TryRemoveItem is used with rebuildTree set to false
- Build fails with IL2CPP error when building on Android platform in a specific project
Resolution Note:
AndroidJNI.FindClass can only be called from a thread that is attached to Java, otherwise it will return null. Call AndroidJNI.AttachCurrentThread to attach thread.
Resolution Note (2023.2.X):
AndroidJNI.FindClass can only be called from a thread that is attached to Java, otherwise it will return null. Call AndroidJNI.AttachCurrentThread to attach thread.