Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cb2d94a9 authored by Michael Hoisie's avatar Michael Hoisie
Browse files

Print an informative message when trying to register an unsupported class

Previously, if there was a class name passed in the core_native_classes
or graphics_native_classes system property, and the class name wasn't
present in the JNI registration map, the process would crash, and you
would see the generic error message:

    out_of_range was thrown in -fno-exceptions mode with message
    "unordered_map::at: key not found"

Update the logic to print an actionable error message and return an
error, which causes JNI registration to fail.

Bug: 437898369
FLAG: EXEMPT host-only
Test: Robolectric test in Google3
Change-Id: I370a01ae3fe9aee4b0d023bbd4406a7d07afc456
parent 1cf0749b
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -159,8 +159,14 @@ static const std::unordered_map<std::string, RegJNIRec> gRegJNIMap = {
static int register_jni_procs(const std::unordered_map<std::string, RegJNIRec>& jniRegMap,
                              const vector<string>& classesToRegister, JNIEnv* env) {
    for (const string& className : classesToRegister) {
        if (jniRegMap.at(className).mProc(env) < 0) {
            return -1;
        auto it = jniRegMap.find(className);
        if (it == jniRegMap.end()) {
            fprintf(stderr, "Missing registration function for %s\n", className.c_str());
            return JNI_ERR;
        }
        if (it->second.mProc(env) < 0) {
            fprintf(stderr, "Failed to register class %s\n", className.c_str());
            return JNI_ERR;
        }
    }

+8 −2
Original line number Diff line number Diff line
@@ -160,8 +160,14 @@ static int register_jni_procs(const std::unordered_map<std::string, RegJNIRec>&
        const vector<string>& classesToRegister, JNIEnv* env) {

    for (const string& className : classesToRegister) {
        if (jniRegMap.at(className).mProc(env) < 0) {
            return -1;
        auto it = jniRegMap.find(className);
        if (it == jniRegMap.end()) {
            fprintf(stderr, "Missing registration function for %s\n", className.c_str());
            return JNI_ERR;
        }
        if (it->second.mProc(env) < 0) {
            fprintf(stderr, "Failed to register class %s\n", className.c_str());
            return JNI_ERR;
        }
    }
    return 0;