Skip to content

Commit 83899a9

Browse files
author
Github Executorch
committed
Summary: Use javaClassStatic() for class references stored in static variables - creates global references safe for persistence
findClassLocal() returns a local reference. Storing it in static auto exceptionClass = ... could result in potential 'invalid local reference:' as local references become invalid when the JNI frame ends Test Plan: Reviewers: Subscribers: Tasks: Tags:
1 parent f24351a commit 83899a9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

extension/android/jni/jni_helper.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010

1111
namespace executorch::jni_helper {
1212

13+
// Define the JavaClass wrapper
14+
struct JExecutorchRuntimeException : public facebook::jni::JavaClass<JExecutorchRuntimeException> {
15+
static constexpr auto kJavaDescriptor = "Lorg/pytorch/executorch/ExecutorchRuntimeException;";
16+
};
17+
1318
void throwExecutorchException(uint32_t errorCode, const std::string& details) {
1419
// Get the current JNI environment
1520
auto env = facebook::jni::Environment::current();
1621

1722
// Find the Java ExecutorchRuntimeException class
18-
static auto exceptionClass = facebook::jni::findClassLocal(
19-
"org/pytorch/executorch/ExecutorchRuntimeException");
23+
static const auto exceptionClass = JExecutorchRuntimeException::javaClassStatic();
2024

2125
// Find the static factory method: makeExecutorchException(int, String)
2226
static auto makeExceptionMethod =

0 commit comments

Comments
 (0)