Fix InsertDexFileInToClassLoader to handle null class loaders
Maybe used by legacy apps. This functionality is planned for
deprecation.
Bug: 27954959
Change-Id: I20a3f9de2ca743b2ba2a26d591c09624ead4127e
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 5ea5f8e..da9763f 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -7758,12 +7758,11 @@
void ClassLinker::InsertDexFileInToClassLoader(mirror::Object* dex_file,
mirror::ClassLoader* class_loader) {
DCHECK(dex_file != nullptr);
- DCHECK(class_loader != nullptr);
Thread* const self = Thread::Current();
WriterMutexLock mu(self, *Locks::classlinker_classes_lock_);
- ClassTable* const table = class_loader->GetClassTable();
+ ClassTable* const table = ClassTableForClassLoader(class_loader);
DCHECK(table != nullptr);
- if (table->InsertDexFile(dex_file)) {
+ if (table->InsertDexFile(dex_file) && class_loader != nullptr) {
// It was not already inserted, perform the write barrier to let the GC know the class loader's
// class table was modified.
Runtime::Current()->GetHeap()->WriteBarrierEveryFieldOf(class_loader);