pEp for Java
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

41 lines
1.1 KiB

#include "jniutils.hh"
#include <stdexcept>
#include <typeinfo>
#include <assert.h>
#include <string>
namespace pEp {
namespace JNIAdapter {
jfieldID getFieldID(
JNIEnv *env,
const char *classname,
const char *fieldname,
const char *signature
)
{
jclass engine = env->FindClass(classname);
assert(engine);
if (engine == NULL) {
jclass ex = env->FindClass("java/lang/NoClassDefFoundError");
assert(ex);
env->ThrowNew(ex, classname);
throw std::bad_cast();
}
jfieldID field = env->GetFieldID(engine, fieldname, signature);
assert(field);
if (field == NULL) {
jclass ex = env->FindClass("java/lang/NoSuchFieldError");
assert(ex);
env->ThrowNew(ex, fieldname);
throw std::invalid_argument(std::string(fieldname));
}
return field;
}
};
};