Merge pull request #303 from psader/feature/fix_reflext_indexerror

Fix bad JavaException in _getitem
This commit is contained in:
Mathieu Virbel 2017-12-11 18:05:42 +01:00 committed by GitHub
commit 5d1e563fd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -105,6 +105,16 @@ cdef void populate_args(JNIEnv *j_env, tuple definition_args, jvalue *j_args, ar
j_env, argtype[1:], py_arg)
cdef convert_jstring_to_python(JNIEnv *j_env, jstring string):
c_str = <char *>j_env[0].GetStringUTFChars(j_env, string, NULL)
py_str = <bytes>c_str
j_env[0].ReleaseStringUTFChars(j_env, string, c_str)
if PY_MAJOR_VERSION < 3:
return py_str
else:
return py_str.decode('utf-8')
cdef convert_jobject_to_python(JNIEnv *j_env, definition, jobject j_object):
# Convert a Java Object to a Python object, according to the definition.
# If the definition is a java/lang/Object, then try to determine what is it

View File

@ -77,7 +77,7 @@ cdef void check_exception(JNIEnv *j_env) except *:
getStackTrace = j_env[0].GetMethodID(j_env, cls_throwable, "getStackTrace", "()[Ljava/lang/StackTraceElement;");
e_msg = j_env[0].CallObjectMethod(j_env, exc, getMessage);
pymsg = None if e_msg == NULL else convert_jobject_to_python(j_env, <bytes> 'Ljava/lang/String;', e_msg)
pymsg = None if e_msg == NULL else convert_jstring_to_python(j_env, e_msg)
pystack = []
_append_exception_trace_messages(j_env, pystack, exc, getCause, getStackTrace, toString)

View File

@ -226,7 +226,7 @@ def autoclass(clsname):
# initialize the subclass before getting the Class.forName
# otherwise isInstance does not know of the subclass
mock_exception_object = autoclass(e.classname)()
if Class.forName("java.lang.IndexOutOfBoundsException").isInstance(mock_exception_object):
if find_javaclass("java.lang.IndexOutOfBoundsException").isInstance(mock_exception_object):
# python for...in iteration checks for end of list by waiting for IndexError
raise IndexError()
else: