ART: Null thread_name check for loggings in rare occasions.

Passing null char* to ostream::operator<< is undefined and can cause
a crash (for instance when libc++ is used) instead of printing the log.

Bug: None (crbug.com/531282)
Test: None

Change-Id: Ieb1f0fc50723b06e72b66b1da7b6abe58d5b9a02
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 6812105..b86e56b 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -774,14 +774,16 @@
 Thread* Thread::Attach(const char* thread_name, bool as_daemon, PeerAction peer_action) {
   Runtime* runtime = Runtime::Current();
   if (runtime == nullptr) {
-    LOG(ERROR) << "Thread attaching to non-existent runtime: " << thread_name;
+    LOG(ERROR) << "Thread attaching to non-existent runtime: " <<
+        ((thread_name != nullptr) ? thread_name : "(Unnamed)");
     return nullptr;
   }
   Thread* self;
   {
     MutexLock mu(nullptr, *Locks::runtime_shutdown_lock_);
     if (runtime->IsShuttingDownLocked()) {
-      LOG(WARNING) << "Thread attaching while runtime is shutting down: " << thread_name;
+      LOG(WARNING) << "Thread attaching while runtime is shutting down: " <<
+          ((thread_name != nullptr) ? thread_name : "(Unnamed)");
       return nullptr;
     } else {
       Runtime::Current()->StartThreadBirth();