Tweaks to DexFile defineClass JNI code

Change-Id: I248f5e8fc500b540c9100a09507d5d644f73f1ff
diff --git a/src/dalvik_system_DexFile.cc b/src/dalvik_system_DexFile.cc
index 7680e0f..41110d3 100644
--- a/src/dalvik_system_DexFile.cc
+++ b/src/dalvik_system_DexFile.cc
@@ -24,6 +24,7 @@
 #include "runtime.h"
 #include "zip_archive.h"
 #include "toStringArray.h"
+#include "ScopedLocalRef.h"
 #include "ScopedUtfChars.h"
 
 #include "JniConstants.h" // Last to avoid problems with LOG redefinition.
@@ -181,14 +182,14 @@
     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] = {
+    static const char* ignored_exception_classes[] = {
         "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)) {
+    for (size_t i = 0; i < arraysize(ignored_exception_classes); i++) {
+      ScopedLocalRef<jclass> exception_class(env, env->FindClass(ignored_exception_classes[i]));
+      if (env->IsInstanceOf(exception, exception_class.get())) {
         clear_exception = true;
         break;
       }