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

8 years ago
8 years ago
8 years ago
  1. #include "jniutils.hh"
  2. #include <stdexcept>
  3. #include <typeinfo>
  4. #include <assert.h>
  5. #include <string>
  6. namespace pEp {
  7. namespace JNIAdapter {
  8. jfieldID getFieldID(
  9. JNIEnv *env,
  10. const char *classname,
  11. const char *fieldname,
  12. const char *signature
  13. )
  14. {
  15. jclass engine = env->FindClass(classname);
  16. assert(engine);
  17. if (engine == NULL) {
  18. jclass ex = env->FindClass("java/lang/NoClassDefFoundError");
  19. assert(ex);
  20. env->ThrowNew(ex, classname);
  21. throw std::bad_cast();
  22. }
  23. jfieldID field = env->GetFieldID(engine, fieldname, signature);
  24. assert(field);
  25. if (field == NULL) {
  26. jclass ex = env->FindClass("java/lang/NoSuchFieldError");
  27. assert(ex);
  28. env->ThrowNew(ex, fieldname);
  29. throw std::invalid_argument(std::string(fieldname));
  30. }
  31. return field;
  32. }
  33. };
  34. };