You can't call initCause on a ClassNotFoundException.

Unlike NoClassDefFoundError, ClassNotFoundException has to be constructed
with a cause, or it will stupidly set a null cause which can't then be
changed.

This patch also fixes incorrect caching of jclass local references in statics,
which I noticed while fixing the test I'd broken.

Change-Id: I017f4a4e4158554427ccb37b650c985add28980c
diff --git a/src/debugger.cc b/src/debugger.cc
index f1e6066..72a4fdd 100644
--- a/src/debugger.cc
+++ b/src/debugger.cc
@@ -1739,10 +1739,9 @@
   Thread* self = Thread::Current();
   JNIEnv* env = self->GetJniEnv();
 
-  static jclass Chunk_class = env->FindClass("org/apache/harmony/dalvik/ddmc/Chunk");
-  static jclass DdmServer_class = env->FindClass("org/apache/harmony/dalvik/ddmc/DdmServer");
-  static jmethodID dispatch_mid = env->GetStaticMethodID(DdmServer_class, "dispatch",
-      "(I[BII)Lorg/apache/harmony/dalvik/ddmc/Chunk;");
+  static jclass Chunk_class = CacheClass(env, "org/apache/harmony/dalvik/ddmc/Chunk");
+  static jclass DdmServer_class = CacheClass(env, "org/apache/harmony/dalvik/ddmc/DdmServer");
+  static jmethodID dispatch_mid = env->GetStaticMethodID(DdmServer_class, "dispatch", "(I[BII)Lorg/apache/harmony/dalvik/ddmc/Chunk;");
   static jfieldID data_fid = env->GetFieldID(Chunk_class, "data", "[B");
   static jfieldID length_fid = env->GetFieldID(Chunk_class, "length", "I");
   static jfieldID offset_fid = env->GetFieldID(Chunk_class, "offset", "I");
@@ -1836,7 +1835,7 @@
   }
 
   JNIEnv* env = self->GetJniEnv();
-  static jclass DdmServer_class = env->FindClass("org/apache/harmony/dalvik/ddmc/DdmServer");
+  static jclass DdmServer_class = CacheClass(env, "org/apache/harmony/dalvik/ddmc/DdmServer");
   static jmethodID broadcast_mid = env->GetStaticMethodID(DdmServer_class, "broadcast", "(I)V");
   jint event = connect ? 1 /*DdmServer.CONNECTED*/ : 2 /*DdmServer.DISCONNECTED*/;
   env->CallStaticVoidMethod(DdmServer_class, broadcast_mid, event);