From c4489a05433b2878d0598d77bec5d9f6a821ffaa Mon Sep 17 00:00:00 2001
From: Paul Sokolovsky <pfalcon@users.sourceforge.net>
Date: Thu, 1 Oct 2015 01:19:33 -0700
Subject: [PATCH] unix/modjni: Propagate Java exceptions on list access.

---
 unix/modjni.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/unix/modjni.c b/unix/modjni.c
index 04102938a..3e94c0e67 100644
--- a/unix/modjni.c
+++ b/unix/modjni.c
@@ -92,6 +92,16 @@ STATIC bool is_object_type(const char *jtypesig) {
     return false;
 }
 
+STATIC void check_exception(void) {
+    jobject exc = JJ1(ExceptionOccurred);
+    if (exc) {
+        //JJ1(ExceptionDescribe);
+        mp_obj_t py_e = new_jobject(exc);
+        JJ1(ExceptionClear);
+        nlr_raise(mp_obj_new_exception_arg1(&mp_type_Exception, py_e));
+    }
+}
+
 // jclass
 
 STATIC void jclass_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
@@ -200,6 +210,9 @@ STATIC mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
     } else if (value == MP_OBJ_SENTINEL) {
         // load
         jobject el = JJ(CallObjectMethod, self->obj, List_get_mid, idx);
+        if (el == NULL) {
+            check_exception();
+        }
         return new_jobject(el);
     } else {
         // store
-- 
GitLab