Avoid visiting find array class cache as roots

If we visit the find array class cache as roots it will prevent
unloading for any array classes in the cache. This is not ideal
since it may take a long time for the entries to get replaced.

Also added a missed exception check in getDeclaredClasses.

Bug: 22720414

Change-Id: Id34557fd034b3e3967ef629301ee251931937849
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc
index 5da15df..3a73900 100644
--- a/runtime/native/java_lang_Class.cc
+++ b/runtime/native/java_lang_Class.cc
@@ -522,6 +522,10 @@
   }
   if (classes == nullptr) {
     // Return an empty array instead of a null pointer.
+    if (soa.Self()->IsExceptionPending()) {
+      // Pending exception from GetDeclaredClasses.
+      return nullptr;
+    }
     mirror::Class* class_class = mirror::Class::GetJavaLangClass();
     mirror::Class* class_array_class =
         Runtime::Current()->GetClassLinker()->FindArrayClass(soa.Self(), &class_class);