Merge "Fix reflection to throw rather than crash when a type is not loaded." into dalvik-dev
diff --git a/src/java_lang_Class.cc b/src/java_lang_Class.cc
index f4376ec..0ed6cea 100644
--- a/src/java_lang_Class.cc
+++ b/src/java_lang_Class.cc
@@ -116,12 +116,18 @@
   std::vector<Field*> fields;
   for (size_t i = 0; i < c->NumInstanceFields(); ++i) {
     Field* f = c->GetInstanceField(i);
+    if (env->ExceptionOccurred()) {
+      return NULL;
+    }
     if (IsVisibleField(f, publicOnly)) {
       fields.push_back(f);
     }
   }
   for (size_t i = 0; i < c->NumStaticFields(); ++i) {
     Field* f = c->GetStaticField(i);
+    if (env->ExceptionOccurred()) {
+      return NULL;
+    }
     if (IsVisibleField(f, publicOnly)) {
       fields.push_back(f);
     }
@@ -147,12 +153,18 @@
   std::vector<Method*> methods;
   for (size_t i = 0; i < c->NumVirtualMethods(); ++i) {
     Method* m = c->GetVirtualMethod(i);
+    if (env->ExceptionOccurred()) {
+      return NULL;
+    }
     if (IsVisibleMethod(m, publicOnly)) {
       methods.push_back(m);
     }
   }
   for (size_t i = 0; i < c->NumDirectMethods(); ++i) {
     Method* m = c->GetDirectMethod(i);
+    if (env->ExceptionOccurred()) {
+      return NULL;
+    }
     if (IsVisibleMethod(m, publicOnly)) {
       methods.push_back(m);
     }