Skip to content

Commit

Permalink
fix: Correctly resolve classes with FindClass(..)
Browse files Browse the repository at this point in the history
`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.

Fixes: facebook/yoga#1120
  • Loading branch information
evancharlton committed Aug 30, 2022
1 parent 3afef3c commit c73c6a6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static int YGJNILogFunc(
if (*jloggerPtr) {
JNIEnv* env = getCurrentEnv();

jclass cl = env->FindClass("Lcom/facebook/yoga/YogaLogLevel;");
jclass cl = env->FindClass("com/facebook/yoga/YogaLogLevel");
static const jmethodID smethodId =
facebook::yoga::vanillajni::getStaticMethodId(
env, cl, "fromInt", "(I)Lcom/facebook/yoga/YogaLogLevel;");
Expand Down Expand Up @@ -386,7 +386,7 @@ static void jni_YGNodeCalculateLayoutJNI(
}
} catch (const std::logic_error& ex) {
env->ExceptionClear();
jclass cl = env->FindClass("Ljava/lang/IllegalStateException;");
jclass cl = env->FindClass("java/lang/IllegalStateException");
static const jmethodID methodId = facebook::yoga::vanillajni::getMethodId(
env, cl, "<init>", "(Ljava/lang/String;)V");
auto throwable = env->NewObject(cl, methodId, env->NewStringUTF(ex.what()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace yoga {
namespace vanillajni {

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

0 comments on commit c73c6a6

Please sign in to comment.