Merge pull request #66 from zielmicha/master

Check for exception after calling constructor
This commit is contained in:
Mathieu Virbel 2013-08-02 07:04:16 -07:00
commit afc1d9d788
2 changed files with 6 additions and 0 deletions

View File

@ -218,11 +218,14 @@ cdef class JavaClass(object):
# create the object
j_self = j_env[0].NewObjectA(j_env, self.j_cls,
constructor, j_args)
check_exception(j_env)
if j_self == NULL:
raise JavaException('Unable to instanciate {0}'.format(
self.__javaclass__))
self.j_self = create_local_ref(j_env, j_self)
j_env[0].DeleteLocalRef(j_env, j_self)
finally:
if j_args != NULL:
free(j_args)

View File

@ -77,6 +77,9 @@ cdef bytes lookup_java_object_name(JNIEnv *j_env, jobject j_obj):
cdef jmethodID jmeth = j_env[0].GetMethodID(j_env, jcls2, 'getName', '()Ljava/lang/String;')
cdef jobject js = j_env[0].CallObjectMethod(j_env, jcls, jmeth)
name = convert_jobject_to_python(j_env, b'Ljava/lang/String;', js)
j_env[0].DeleteLocalRef(j_env, js)
j_env[0].DeleteLocalRef(j_env, jcls)
j_env[0].DeleteLocalRef(j_env, jcls2)
return name.replace('.', '/')