[libbluray-devel] bdj_make_object(): check for errors

hpi1 git at videolan.org
Thu Mar 30 11:55:17 CEST 2017


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Mar 27 15:32:35 2017 +0300| [b72012a0dc548c6639252db2b533bcf4c09be0dd] | committer: hpi1

bdj_make_object(): check for errors

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=b72012a0dc548c6639252db2b533bcf4c09be0dd
---

 src/libbluray/bdj/native/util.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/libbluray/bdj/native/util.c b/src/libbluray/bdj/native/util.c
index bf4e97a..a4371a2 100644
--- a/src/libbluray/bdj/native/util.c
+++ b/src/libbluray/bdj/native/util.c
@@ -30,19 +30,31 @@
 
 jobject bdj_make_object(JNIEnv* env, const char* name, const char* sig, ...)
 {
-    jclass obj_class = (*env)->FindClass(env, name);
-    jmethodID obj_constructor = (*env)->GetMethodID(env, obj_class, "<init>", sig);
+    va_list ap;
+    jclass obj_class;
+    jmethodID obj_constructor;
+    jobject obj;
 
+    obj_class = (*env)->FindClass(env, name);
     if (!obj_class) {
         BD_DEBUG(DBG_BDJ | DBG_CRIT, "Class %s not found\n", name);
         return NULL;
     }
 
-    va_list ap;
+    obj_constructor = (*env)->GetMethodID(env, obj_class, "<init>", sig);
+    if (!obj_constructor) {
+        BD_DEBUG(DBG_BDJ | DBG_CRIT, "Class %s constructor %s not found\n", name, sig);
+        return NULL;
+    }
+
     va_start(ap, sig);
-    jobject obj = (*env)->NewObjectV(env, obj_class, obj_constructor, ap);
+    obj = (*env)->NewObjectV(env, obj_class, obj_constructor, ap);
     va_end(ap);
 
+    if (!obj) {
+        BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to create %s\n", name);
+    }
+
     return obj;
 }
 



More information about the libbluray-devel mailing list