From 6c729acd12933d79aae3ef05dbdecfa0feb96bf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kry=C5=A1tof=20Wold=C5=99ich?= <31292499+krystofwoldrich@users.noreply.github.com> Date: Fri, 23 Jun 2023 04:49:15 -0700 Subject: [PATCH] Use new getCanonicalName and getMessage methods exposed by fbjni (#37879) Summary: When a new version of `fbjni` is released, we can simplify `getName` and `getMessage` calls on throwables. ## Changelog: [ANDROID] [CHANGED] - Use new `getCanonicalName` and `getMessage` methods exposed by `fbjni` Pull Request resolved: https://github.com/facebook/react-native/pull/37879 Test Plan: https://github.com/facebookincubator/fbjni/pull/78 Reviewed By: cortinico Differential Revision: D46966561 Pulled By: javache fbshipit-source-id: f30720a30146cf8fe5125336435a1512063c253d --- packages/react-native/ReactAndroid/gradle.properties | 2 +- .../ReactAndroid/hermes-engine/build.gradle | 2 +- .../platform/android/ReactCommon/JavaTurboModule.cpp | 12 +++--------- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/react-native/ReactAndroid/gradle.properties b/packages/react-native/ReactAndroid/gradle.properties index 48f489a1d0e984..c98e45ce5e8517 100644 --- a/packages/react-native/ReactAndroid/gradle.properties +++ b/packages/react-native/ReactAndroid/gradle.properties @@ -7,7 +7,7 @@ ANDROIDX_AUTOFILL_VERSION=1.1.0 ANDROIDX_TEST_VERSION=1.1.0 ANDROIDX_TRACING_VERSION=1.1.0 ASSERTJ_VERSION=3.21.0 -FBJNI_VERSION=0.3.0 +FBJNI_VERSION=0.4.0 FRESCO_VERSION=2.5.0 INFER_ANNOTATIONS_VERSION=0.18.0 JAVAX_INJECT_VERSION=1 diff --git a/packages/react-native/ReactAndroid/hermes-engine/build.gradle b/packages/react-native/ReactAndroid/hermes-engine/build.gradle index 15a2f49b0969a3..f2a4f8d675df17 100644 --- a/packages/react-native/ReactAndroid/hermes-engine/build.gradle +++ b/packages/react-native/ReactAndroid/hermes-engine/build.gradle @@ -222,7 +222,7 @@ android { } dependencies { - implementation("com.facebook.fbjni:fbjni:0.3.0") + implementation("com.facebook.fbjni:fbjni:0.4.0") implementation("com.facebook.soloader:soloader:0.10.4") implementation("com.facebook.yoga:proguard-annotations:1.19.0") implementation("androidx.annotation:annotation:1.3.0") diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp index 616861539d1749..0940a6ea48a1e2 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp @@ -430,15 +430,9 @@ jsi::JSError convertThrowableToJSError( } jsi::Object cause(runtime); - auto getName = throwable->getClass() - ->getClass() - ->getMethod()>("getName"); - auto getMessage = - throwable->getClass()->getMethod()>( - "getMessage"); - auto message = getMessage(throwable)->toStdString(); - cause.setProperty( - runtime, "name", getName(throwable->getClass())->toStdString()); + auto name = throwable->getClass()->getCanonicalName()->toStdString(); + auto message = throwable->getMessage()->toStdString(); + cause.setProperty(runtime, "name", name); cause.setProperty(runtime, "message", message); cause.setProperty(runtime, "stackElements", std::move(stackElements));