Fix JDWP crash when reporting exception

The exception's throw location may be null so we need to handle that
case. Also fixes a memset issue.

Bug: 17571297
(cherry picked from commit bbb63897d7f2d99219cb50721fe530521e08ddff)

Change-Id: Iedebb58f9460c5f04913c269200e51161bda1ba9
diff --git a/runtime/debugger.cc b/runtime/debugger.cc
index aced954..2cef855 100644
--- a/runtime/debugger.cc
+++ b/runtime/debugger.cc
@@ -845,7 +845,9 @@
 }
 
 std::string Dbg::GetClassName(mirror::Class* klass) {
-  DCHECK(klass != nullptr);
+  if (klass == nullptr) {
+    return "NULL";
+  }
   std::string temp;
   return DescriptorToName(klass->GetDescriptor(&temp));
 }
@@ -1466,6 +1468,9 @@
 }
 
 bool Dbg::MatchType(mirror::Class* event_class, JDWP::RefTypeId class_id) {
+  if (event_class == nullptr) {
+    return false;
+  }
   JDWP::JdwpError error;
   mirror::Class* expected_class = DecodeClass(class_id, &error);
   CHECK(expected_class != nullptr);
@@ -1490,7 +1495,7 @@
 void Dbg::SetJdwpLocation(JDWP::JdwpLocation* location, mirror::ArtMethod* m, uint32_t dex_pc)
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
   if (m == nullptr) {
-    memset(&location, 0, sizeof(*location));
+    memset(location, 0, sizeof(*location));
   } else {
     mirror::Class* c = m->GetDeclaringClass();
     location->type_tag = GetTypeTag(c);
@@ -1502,11 +1507,18 @@
 
 std::string Dbg::GetMethodName(JDWP::MethodId method_id) {
   mirror::ArtMethod* m = FromMethodId(method_id);
+  if (m == nullptr) {
+    return "NULL";
+  }
   return m->GetName();
 }
 
 std::string Dbg::GetFieldName(JDWP::FieldId field_id) {
-  return FromFieldId(field_id)->GetName();
+  mirror::ArtField* f = FromFieldId(field_id);
+  if (f == nullptr) {
+    return "NULL";
+  }
+  return f->GetName();
 }
 
 /*
diff --git a/runtime/jdwp/jdwp_event.cc b/runtime/jdwp/jdwp_event.cc
index d61660b..7c8c63c 100644
--- a/runtime/jdwp/jdwp_event.cc
+++ b/runtime/jdwp/jdwp_event.cc
@@ -1125,12 +1125,19 @@
   DCHECK(exception_object != nullptr);
   DCHECK(pThrowLoc != nullptr);
   DCHECK(pCatchLoc != nullptr);
-  DCHECK(pThrowLoc->method != nullptr);
-  DCHECK_EQ(pThrowLoc->method->IsStatic(), thisPtr == nullptr);
+  if (pThrowLoc->method != nullptr) {
+    DCHECK_EQ(pThrowLoc->method->IsStatic(), thisPtr == nullptr);
+  } else {
+    VLOG(jdwp) << "Unexpected: exception event with empty throw location";
+  }
 
   ModBasket basket;
   basket.pLoc = pThrowLoc;
-  basket.locationClass = pThrowLoc->method->GetDeclaringClass();
+  if (pThrowLoc->method != nullptr) {
+    basket.locationClass = pThrowLoc->method->GetDeclaringClass();
+  } else {
+    basket.locationClass = nullptr;
+  }
   basket.thread = Thread::Current();
   basket.className = Dbg::GetClassName(basket.locationClass);
   basket.exceptionClass = exception_object->GetClass();