Fix 086-null-super and 087-gc-after-link

Parallel run-test means that the dex files for 086 and 087 are no longer
always in test.jar. Correct the behavior of the class linker when
Classloader.loadClass returns null to be the behavior of Dalvik.

Change-Id: Icf6363e118d03a01060012ac558b5f1a484d74f9
diff --git a/src/dalvik_system_DexFile.cc b/src/dalvik_system_DexFile.cc
index 7fce25f..7680e0f 100644
--- a/src/dalvik_system_DexFile.cc
+++ b/src/dalvik_system_DexFile.cc
@@ -176,7 +176,26 @@
   class_linker->RegisterDexFile(*dex_file);
   Class* result = class_linker->DefineClass(descriptor, class_loader, *dex_file, *dex_class_def);
   if (env->ExceptionCheck()) {
+    // Remember exception and clear it
+    jthrowable exception = env->ExceptionOccurred();
     env->ExceptionClear();
+    // If we threw a "class not found" exception, stifle it, since the contract in the higher
+    // method says we simply return null if the class is not found.
+    static const char* ignored_exception_classes[2] = {
+        "java/lang/ClassNotFoundException",
+        "java/lang/NoClassDefFoundError"
+    };
+    bool clear_exception = false;
+    for (int i = 0; i < 2; i++) {
+      jclass exception_class = env->FindClass(ignored_exception_classes[i]);
+      if (env->IsInstanceOf(exception, exception_class)) {
+        clear_exception = true;
+        break;
+      }
+    }
+    if (!clear_exception) {
+      env->Throw(exception);
+    }
     return NULL;
   }
   return AddLocalReference<jclass>(env, result);