OSDN Git Service

Move DCHECK into loop.
authorAart Bik <ajcbik@google.com>
Mon, 4 Apr 2016 21:19:01 +0000 (14:19 -0700)
committerAart Bik <ajcbik@google.com>
Mon, 4 Apr 2016 21:19:01 +0000 (14:19 -0700)
Rationale:
Since pointer is non-null on loop entry, moving the check
into the while loop (rather than after) gives a more friendly
error message in debug mode when something goes wrong.

BUG=27825731
BUG=27627004

Change-Id: I2ea67b3ab6c4edc6815fea38a436e5c3c194e540

runtime/mirror/class.cc

index 7900eac..a36091f 100644 (file)
@@ -880,9 +880,10 @@ mirror::Class* Class::GetCommonSuperClass(Handle<Class> klass) {
   DCHECK(!IsInterface());
   mirror::Class* common_super_class = this;
   while (!common_super_class->IsAssignableFrom(klass.Get())) {
-    common_super_class = common_super_class->GetSuperClass();
+    mirror::Class* old_common = common_super_class;
+    common_super_class = old_common->GetSuperClass();
+    DCHECK(common_super_class != nullptr) << PrettyClass(old_common);
   }
-  DCHECK(common_super_class != nullptr);
   return common_super_class;
 }