Fix crash in JDWP ReferenceType.SourceFile command
Updates Dbg::GetSourceFile to return ABSENT_INFORMATION error code when
Class::GetSourceFile returns nullptr. This happens if the class has no source
file information.
Updates Class:GetSourceFile to return nullptr for classes which have no
ClassDef item like generated classes. This allows to remove the IsProxyClass
test from Dbg::GetSourceFile. Adds this test in proxy_test.
Bug: 15426710
Change-Id: I019da4ced83778d5264484c43b225f8b5c95632e
diff --git a/runtime/debugger.cc b/runtime/debugger.cc
index 984f287..07cb9d1 100644
--- a/runtime/debugger.cc
+++ b/runtime/debugger.cc
@@ -1131,13 +1131,14 @@
JDWP::JdwpError Dbg::GetSourceFile(JDWP::RefTypeId class_id, std::string& result) {
JDWP::JdwpError status;
mirror::Class* c = DecodeClass(class_id, status);
- if (c == NULL) {
+ if (c == nullptr) {
return status;
}
- if (c->IsProxyClass()) {
+ const char* source_file = c->GetSourceFile();
+ if (source_file == nullptr) {
return JDWP::ERR_ABSENT_INFORMATION;
}
- result = c->GetSourceFile();
+ result = source_file;
return JDWP::ERR_NONE;
}
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index 4869b45..c3aac5e 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -771,7 +771,10 @@
std::string descriptor(GetDescriptor());
const DexFile& dex_file = GetDexFile();
const DexFile::ClassDef* dex_class_def = GetClassDef();
- CHECK(dex_class_def != nullptr) << "No class def for class " << PrettyClass(this);
+ if (dex_class_def == nullptr) {
+ // Generated classes have no class def.
+ return nullptr;
+ }
return dex_file.GetSourceFile(*dex_class_def);
}
diff --git a/runtime/proxy_test.cc b/runtime/proxy_test.cc
index f38fb21..9724bcc 100644
--- a/runtime/proxy_test.cc
+++ b/runtime/proxy_test.cc
@@ -128,12 +128,12 @@
ASSERT_TRUE(proxy_class->IsProxyClass());
ASSERT_TRUE(proxy_class->IsInitialized());
- // Check ClassHelper for proxy.
- EXPECT_EQ(proxy_class->NumDirectInterfaces(), 2U); // Interfaces$I and Interfaces$J.
+ EXPECT_EQ(2U, proxy_class->NumDirectInterfaces()); // Interfaces$I and Interfaces$J.
EXPECT_EQ(I.Get(), mirror::Class::GetDirectInterface(soa.Self(), proxy_class, 0));
EXPECT_EQ(J.Get(), mirror::Class::GetDirectInterface(soa.Self(), proxy_class, 1));
std::string proxy_class_descriptor(proxy_class->GetDescriptor());
EXPECT_STREQ("L$Proxy1234;", proxy_class_descriptor.c_str());
+ EXPECT_EQ(nullptr, proxy_class->GetSourceFile());
}
// Creates a proxy class and check FieldHelper works correctly.