Skip to content

Commit 361b310

Browse files
evancharltonfacebook-github-bot
authored andcommitted
fix: Correctly resolve classes with FindClass(..) (#34533)
Summary: `JNIEnv`'s `FindClass(..)` function takes the classes in the standard `foo/bar/Baz` class specification (unless they're special, like arrays). Specifying them with `Lfoo/bar/Baz;` results in a `ClassNotFoundException` being raised -- which is especially unhelpful when intending to re-throw an exception. The docs for `JNIEnv#FindClass(..)` can be found [here][jnienv]. [jnienv]: https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html#:~:text=The%20name%20argument,java/lang/String%22 ## Changelog [Android] [Fixed] - Correctly resolve classes with FindClass(..) Pull Request resolved: #34533 Test Plan: No exact test plan. However, if an exception is thrown during the rendering process, a fatal `ClassNotFoundException` is raised, rather than having the error be passed up to the `ReactNativeManager`. Fixes: facebook/yoga#1120 Reviewed By: amir-shalem Differential Revision: D39133326 Pulled By: jacdebug fbshipit-source-id: 86283b7d21aed49ed0e9027b2aef85f0108cdf9a
1 parent df0b690 commit 361b310

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static int YGJNILogFunc(
147147
if (*jloggerPtr) {
148148
JNIEnv* env = getCurrentEnv();
149149

150-
jclass cl = env->FindClass("Lcom/facebook/yoga/YogaLogLevel;");
150+
jclass cl = env->FindClass("com/facebook/yoga/YogaLogLevel");
151151
static const jmethodID smethodId =
152152
facebook::yoga::vanillajni::getStaticMethodId(
153153
env, cl, "fromInt", "(I)Lcom/facebook/yoga/YogaLogLevel;");
@@ -386,7 +386,7 @@ static void jni_YGNodeCalculateLayoutJNI(
386386
}
387387
} catch (const std::logic_error& ex) {
388388
env->ExceptionClear();
389-
jclass cl = env->FindClass("Ljava/lang/IllegalStateException;");
389+
jclass cl = env->FindClass("java/lang/IllegalStateException");
390390
static const jmethodID methodId = facebook::yoga::vanillajni::getMethodId(
391391
env, cl, "<init>", "(Ljava/lang/String;)V");
392392
auto throwable = env->NewObject(cl, methodId, env->NewStringUTF(ex.what()));

ReactAndroid/src/main/jni/first-party/yogajni/jni/YogaJniException.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace yoga {
1515
namespace vanillajni {
1616

1717
YogaJniException::YogaJniException() {
18-
jclass cl = getCurrentEnv()->FindClass("Ljava/lang/RuntimeException;");
18+
jclass cl = getCurrentEnv()->FindClass("java/lang/RuntimeException");
1919
static const jmethodID methodId = facebook::yoga::vanillajni::getMethodId(
2020
getCurrentEnv(), cl, "<init>", "()V");
2121
auto throwable = getCurrentEnv()->NewObject(cl, methodId);

0 commit comments

Comments
 (0)