Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Missing exception handlers #11

Closed
RobDickinson opened this issue Oct 4, 2018 · 1 comment
Closed

Missing exception handlers #11

RobDickinson opened this issue Oct 4, 2018 · 1 comment
Labels

Comments

@RobDickinson
Copy link
Member

RobDickinson commented Oct 4, 2018

There are a number of places (like the example below) where proper exception handling is missing in the case an exception is thrown in a callback.

extern "C" JNIEXPORT void JNICALL Java_io_pmem_pmemkv_KVEngine_kvengine_1each_1string
        (JNIEnv* env, jobject obj, jlong pointer, jobject callback) {

    const auto cb = [](void* context, int32_t keybytes, const char* key, int32_t valuebytes, const char* value) {
        const auto c = ((CallbackContext*) context);
        const auto ckey = c->env->NewStringUTF(key);
        const auto cvalue = c->env->NewStringUTF(value);
        c->env->CallVoidMethod(c->callback, c->mid, ckey, cvalue);  // this could throw an exception
        c->env->DeleteLocalRef(ckey);  // on exception, this will be skipped
        c->env->DeleteLocalRef(cvalue);  // on exception, this will be skipped
    };

    const auto cls = env->GetObjectClass(callback);
    const auto mid = env->GetMethodID(cls, "process", "(Ljava/lang/String;Ljava/lang/String;)V");
    CallbackContext cxt = {env, callback, mid};
    const auto engine = (KVEngine*) pointer;
    pmemkv::kvengine_each(engine, &cxt, cb);

}

Obviously this means we also need test cases where mock callbacks are throwing exceptions.

@lukaszstolarczuk
Copy link
Member

partially done, to be continued on java repository.

ref. pmem/pmemkv-java#69

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants