summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hoisie <hoisie@google.com>2023-11-17 23:25:11 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-11-17 23:25:11 +0000
commitb5e171dda6e144052637b01bcf30a5a0867b43cf (patch)
treed5b55f57cffbfc953f386f4faa7c434412818b3c
parent8a35fbc5a0daf2375df0498e976f0d7d34ecaeb0 (diff)
parent294abb937bcc7d1fd966478379d54bc3ca113580 (diff)
downloadbase-b5e171dda6e144052637b01bcf30a5a0867b43cf.tar.gz
Merge "Print an error if the ICU dat file does not exist" into android12-hostruntime-dev
-rw-r--r--core/jni/RobolectricNativeRuntime.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/core/jni/RobolectricNativeRuntime.cpp b/core/jni/RobolectricNativeRuntime.cpp
index 42cf75d68813..0d41bd2d7be3 100644
--- a/core/jni/RobolectricNativeRuntime.cpp
+++ b/core/jni/RobolectricNativeRuntime.cpp
@@ -3,6 +3,7 @@
#include <string>
#include <android/graphics/jni_runtime.h>
+#include <sys/stat.h>
#include "core_jni_helpers.h"
#include "jni.h"
#include "unicode/locid.h"
@@ -77,6 +78,11 @@ static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env
using namespace android;
+int fileExists(const char* filename) {
+ struct stat buffer;
+ return (stat(filename, &buffer) == 0);
+}
+
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
javaVM = vm;
JNIEnv* env = nullptr;
@@ -116,6 +122,10 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
env->NewStringUTF("icu.dir"),
env->NewStringUTF(""));
const char* path = env->GetStringUTFChars(stringPath, 0);
+ if (!fileExists(path)) {
+ fprintf(stderr, "Invalid ICU dat file path '%s'\n", path);
+ return JNI_ERR;
+ }
u_setDataDirectory(path);
env->ReleaseStringUTFChars(stringPath, path);