Replace NULL with nullptr

Also fixed some lines that were too long, and a few other minor
details.

Change-Id: I6efba5fb6e03eb5d0a300fddb2a75bf8e2f175cb
diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc
index 87ae64d..4f97d20 100644
--- a/runtime/native/dalvik_system_DexFile.cc
+++ b/runtime/native/dalvik_system_DexFile.cc
@@ -109,7 +109,7 @@
 //
 //   NullableScopedUtfChars name(env, javaName);
 //   if (env->ExceptionCheck()) {
-//       return NULL;
+//       return null;
 //   }
 //   // ... use name.c_str()
 //
@@ -117,7 +117,7 @@
 class NullableScopedUtfChars {
  public:
   NullableScopedUtfChars(JNIEnv* env, jstring s) : mEnv(env), mString(s) {
-    mUtfChars = (s != NULL) ? env->GetStringUTFChars(s, NULL) : NULL;
+    mUtfChars = (s != nullptr) ? env->GetStringUTFChars(s, nullptr) : nullptr;
   }
 
   ~NullableScopedUtfChars() {
@@ -149,9 +149,10 @@
   void operator=(const NullableScopedUtfChars&);
 };
 
-static jobject DexFile_openDexFileNative(JNIEnv* env, jclass, jstring javaSourceName, jstring javaOutputName, jint) {
+static jobject DexFile_openDexFileNative(
+    JNIEnv* env, jclass, jstring javaSourceName, jstring javaOutputName, jint) {
   ScopedUtfChars sourceName(env, javaSourceName);
-  if (sourceName.c_str() == NULL) {
+  if (sourceName.c_str() == nullptr) {
     return 0;
   }
   NullableScopedUtfChars outputName(env, javaOutputName);
@@ -224,9 +225,9 @@
   }
 
   ScopedUtfChars class_name(env, javaName);
-  if (class_name.c_str() == NULL) {
+  if (class_name.c_str() == nullptr) {
     VLOG(class_linker) << "Failed to find class_name";
-    return NULL;
+    return nullptr;
   }
   const std::string descriptor(DotToDescriptor(class_name.c_str()));
   const size_t hash(ComputeModifiedUtf8Hash(descriptor.c_str()));
@@ -367,7 +368,7 @@
                          instruction_set.c_str(), defer);
 }
 
-// public API, NULL pkgname
+// public API, null pkgname
 static jboolean DexFile_isDexOptNeeded(JNIEnv* env, jclass, jstring javaFilename) {
   const char* instruction_set = GetInstructionSetString(kRuntimeISA);
   ScopedUtfChars filename(env, javaFilename);
@@ -378,11 +379,14 @@
 
 static JNINativeMethod gMethods[] = {
   NATIVE_METHOD(DexFile, closeDexFile, "(Ljava/lang/Object;)V"),
-  NATIVE_METHOD(DexFile, defineClassNative, "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/Object;)Ljava/lang/Class;"),
+  NATIVE_METHOD(DexFile, defineClassNative,
+                "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/Object;)Ljava/lang/Class;"),
   NATIVE_METHOD(DexFile, getClassNameList, "(Ljava/lang/Object;)[Ljava/lang/String;"),
   NATIVE_METHOD(DexFile, isDexOptNeeded, "(Ljava/lang/String;)Z"),
-  NATIVE_METHOD(DexFile, getDexOptNeeded, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)I"),
-  NATIVE_METHOD(DexFile, openDexFileNative, "(Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/Object;"),
+  NATIVE_METHOD(DexFile, getDexOptNeeded,
+                "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)I"),
+  NATIVE_METHOD(DexFile, openDexFileNative,
+                "(Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/Object;"),
 };
 
 void register_dalvik_system_DexFile(JNIEnv* env) {
diff --git a/runtime/native/dalvik_system_VMDebug.cc b/runtime/native/dalvik_system_VMDebug.cc
index 876e29a..46881b0 100644
--- a/runtime/native/dalvik_system_VMDebug.cc
+++ b/runtime/native/dalvik_system_VMDebug.cc
@@ -104,7 +104,7 @@
   }
 
   ScopedUtfChars traceFilename(env, javaTraceFilename);
-  if (traceFilename.c_str() == NULL) {
+  if (traceFilename.c_str() == nullptr) {
     return;
   }
   Trace::Start(traceFilename.c_str(), fd, bufferSize, flags, Trace::TraceOutputMode::kFile,
@@ -116,7 +116,7 @@
                                                jint bufferSize, jint flags,
                                                jboolean samplingEnabled, jint intervalUs) {
   ScopedUtfChars traceFilename(env, javaTraceFilename);
-  if (traceFilename.c_str() == NULL) {
+  if (traceFilename.c_str() == nullptr) {
     return;
   }
   Trace::Start(traceFilename.c_str(), -1, bufferSize, flags, Trace::TraceOutputMode::kFile,
@@ -156,7 +156,7 @@
 
 static void ThrowUnsupportedOperationException(JNIEnv* env) {
   ScopedObjectAccess soa(env);
-  soa.Self()->ThrowNewException("Ljava/lang/UnsupportedOperationException;", NULL);
+  soa.Self()->ThrowNewException("Ljava/lang/UnsupportedOperationException;", nullptr);
 }
 
 static void VMDebug_startInstructionCounting(JNIEnv* env, jclass) {
@@ -200,15 +200,15 @@
  * error occurs during file handling.
  */
 static void VMDebug_dumpHprofData(JNIEnv* env, jclass, jstring javaFilename, jobject javaFd) {
-  // Only one of these may be NULL.
-  if (javaFilename == NULL && javaFd == NULL) {
+  // Only one of these may be null.
+  if (javaFilename == nullptr && javaFd == nullptr) {
     ScopedObjectAccess soa(env);
     ThrowNullPointerException("fileName == null && fd == null");
     return;
   }
 
   std::string filename;
-  if (javaFilename != NULL) {
+  if (javaFilename != nullptr) {
     ScopedUtfChars chars(env, javaFilename);
     if (env->ExceptionCheck()) {
       return;
@@ -219,7 +219,7 @@
   }
 
   int fd = -1;
-  if (javaFd != NULL) {
+  if (javaFd != nullptr) {
     fd = jniGetFDFromFileDescriptor(env, javaFd);
     if (fd < 0) {
       ScopedObjectAccess soa(env);
diff --git a/runtime/native/dalvik_system_VMRuntime.cc b/runtime/native/dalvik_system_VMRuntime.cc
index 196a231..53bb129 100644
--- a/runtime/native/dalvik_system_VMRuntime.cc
+++ b/runtime/native/dalvik_system_VMRuntime.cc
@@ -114,7 +114,7 @@
 }
 
 static jlong VMRuntime_addressOf(JNIEnv* env, jobject, jobject javaArray) {
-  if (javaArray == NULL) {  // Most likely allocation failed
+  if (javaArray == nullptr) {  // Most likely allocation failed
     return 0;
   }
   ScopedFastNativeObjectAccess soa(env);
@@ -263,17 +263,17 @@
 };
 
 // Based on ClassLinker::ResolveString.
-static void PreloadDexCachesResolveString(Handle<mirror::DexCache> dex_cache, uint32_t string_idx,
-                                          StringTable& strings)
+static void PreloadDexCachesResolveString(
+    Handle<mirror::DexCache> dex_cache, uint32_t string_idx, StringTable& strings)
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
   mirror::String* string = dex_cache->GetResolvedString(string_idx);
-  if (string != NULL) {
+  if (string != nullptr) {
     return;
   }
   const DexFile* dex_file = dex_cache->GetDexFile();
   const char* utf8 = dex_file->StringDataByIdx(string_idx);
   string = strings[utf8];
-  if (string == NULL) {
+  if (string == nullptr) {
     return;
   }
   // LOG(INFO) << "VMRuntime.preloadDexCaches resolved string=" << utf8;
@@ -281,10 +281,11 @@
 }
 
 // Based on ClassLinker::ResolveType.
-static void PreloadDexCachesResolveType(Thread* self, mirror::DexCache* dex_cache, uint32_t type_idx)
+static void PreloadDexCachesResolveType(
+    Thread* self, mirror::DexCache* dex_cache, uint32_t type_idx)
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
   mirror::Class* klass = dex_cache->GetResolvedType(type_idx);
-  if (klass != NULL) {
+  if (klass != nullptr) {
     return;
   }
   const DexFile* dex_file = dex_cache->GetDexFile();
@@ -293,9 +294,9 @@
   if (class_name[1] == '\0') {
     klass = linker->FindPrimitiveClass(class_name[0]);
   } else {
-    klass = linker->LookupClass(self, class_name, ComputeModifiedUtf8Hash(class_name), NULL);
+    klass = linker->LookupClass(self, class_name, ComputeModifiedUtf8Hash(class_name), nullptr);
   }
-  if (klass == NULL) {
+  if (klass == nullptr) {
     return;
   }
   // LOG(INFO) << "VMRuntime.preloadDexCaches resolved klass=" << class_name;
@@ -321,7 +322,7 @@
   Thread* const self = Thread::Current();
   StackHandleScope<1> hs(self);
   Handle<mirror::Class> klass(hs.NewHandle(dex_cache->GetResolvedType(field_id.class_idx_)));
-  if (klass.Get() == NULL) {
+  if (klass.Get() == nullptr) {
     return;
   }
   if (is_static) {
@@ -329,7 +330,7 @@
   } else {
     field = klass->FindInstanceField(dex_cache.Get(), field_idx);
   }
-  if (field == NULL) {
+  if (field == nullptr) {
     return;
   }
   // LOG(INFO) << "VMRuntime.preloadDexCaches resolved field " << PrettyField(field);
@@ -341,13 +342,13 @@
                                           InvokeType invoke_type)
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
   mirror::ArtMethod* method = dex_cache->GetResolvedMethod(method_idx);
-  if (method != NULL) {
+  if (method != nullptr) {
     return;
   }
   const DexFile* dex_file = dex_cache->GetDexFile();
   const DexFile::MethodId& method_id = dex_file->GetMethodId(method_idx);
   mirror::Class* klass = dex_cache->GetResolvedType(method_id.class_idx_);
-  if (klass == NULL) {
+  if (klass == nullptr) {
     return;
   }
   switch (invoke_type) {
@@ -366,7 +367,7 @@
       LOG(FATAL) << "Unreachable - invocation type: " << invoke_type;
       UNREACHABLE();
   }
-  if (method == NULL) {
+  if (method == nullptr) {
     return;
   }
   // LOG(INFO) << "VMRuntime.preloadDexCaches resolved method " << PrettyMethod(method);
@@ -404,7 +405,7 @@
   const std::vector<const DexFile*>& boot_class_path = linker->GetBootClassPath();
   for (size_t i = 0; i< boot_class_path.size(); i++) {
     const DexFile* dex_file = boot_class_path[i];
-    CHECK(dex_file != NULL);
+    CHECK(dex_file != nullptr);
     total->num_strings += dex_file->NumStringIds();
     total->num_fields += dex_file->NumFieldIds();
     total->num_methods += dex_file->NumMethodIds();
@@ -421,29 +422,29 @@
   const std::vector<const DexFile*>& boot_class_path = linker->GetBootClassPath();
   for (size_t i = 0; i< boot_class_path.size(); i++) {
     const DexFile* dex_file = boot_class_path[i];
-    CHECK(dex_file != NULL);
+    CHECK(dex_file != nullptr);
     mirror::DexCache* dex_cache = linker->FindDexCache(*dex_file);
     for (size_t j = 0; j < dex_cache->NumStrings(); j++) {
       mirror::String* string = dex_cache->GetResolvedString(j);
-      if (string != NULL) {
+      if (string != nullptr) {
         filled->num_strings++;
       }
     }
     for (size_t j = 0; j < dex_cache->NumResolvedTypes(); j++) {
       mirror::Class* klass = dex_cache->GetResolvedType(j);
-      if (klass != NULL) {
+      if (klass != nullptr) {
         filled->num_types++;
       }
     }
     for (size_t j = 0; j < dex_cache->NumResolvedFields(); j++) {
       ArtField* field = linker->GetResolvedField(j, dex_cache);
-      if (field != NULL) {
+      if (field != nullptr) {
         filled->num_fields++;
       }
     }
     for (size_t j = 0; j < dex_cache->NumResolvedMethods(); j++) {
       mirror::ArtMethod* method = dex_cache->GetResolvedMethod(j);
-      if (method != NULL) {
+      if (method != nullptr) {
         filled->num_methods++;
       }
     }
@@ -482,7 +483,7 @@
   const std::vector<const DexFile*>& boot_class_path = linker->GetBootClassPath();
   for (size_t i = 0; i< boot_class_path.size(); i++) {
     const DexFile* dex_file = boot_class_path[i];
-    CHECK(dex_file != NULL);
+    CHECK(dex_file != nullptr);
     StackHandleScope<1> hs(soa.Self());
     Handle<mirror::DexCache> dex_cache(hs.NewHandle(linker->FindDexCache(*dex_file)));
 
@@ -504,7 +505,7 @@
            class_def_index++) {
         const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index);
         const uint8_t* class_data = dex_file->GetClassData(class_def);
-        if (class_data == NULL) {
+        if (class_data == nullptr) {
           continue;
         }
         ClassDataItemIterator it(*dex_file, class_data);
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc
index 51a897d..b0d923b 100644
--- a/runtime/native/java_lang_Class.cc
+++ b/runtime/native/java_lang_Class.cc
@@ -42,7 +42,7 @@
     const ScopedFastNativeObjectAccess& soa, jobject java_class)
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
   mirror::Class* c = soa.Decode<mirror::Class*>(java_class);
-  DCHECK(c != NULL);
+  DCHECK(c != nullptr);
   DCHECK(c->IsClass());
   // TODO: we could EnsureInitialized here, rather than on every reflective get/set or invoke .
   // For now, we conservatively preserve the old dalvik behavior. A quick "IsInitialized" check
diff --git a/runtime/native/java_lang_DexCache.cc b/runtime/native/java_lang_DexCache.cc
index 1198c2e..b9f8d01 100644
--- a/runtime/native/java_lang_DexCache.cc
+++ b/runtime/native/java_lang_DexCache.cc
@@ -31,14 +31,14 @@
   // Should only be called while holding the lock on the dex cache.
   DCHECK_EQ(dex_cache->GetLockOwnerThreadId(), soa.Self()->GetThreadId());
   const DexFile* dex_file = dex_cache->GetDexFile();
-  if (dex_file == NULL) {
-    return NULL;
+  if (dex_file == nullptr) {
+    return nullptr;
   }
   void* address = const_cast<void*>(reinterpret_cast<const void*>(dex_file->Begin()));
   jobject byte_buffer = env->NewDirectByteBuffer(address, dex_file->Size());
-  if (byte_buffer == NULL) {
+  if (byte_buffer == nullptr) {
     DCHECK(soa.Self()->IsExceptionPending());
-    return NULL;
+    return nullptr;
   }
 
   jvalue args[1];
diff --git a/runtime/native/java_lang_String.cc b/runtime/native/java_lang_String.cc
index 6afe83b..2d153d4 100644
--- a/runtime/native/java_lang_String.cc
+++ b/runtime/native/java_lang_String.cc
@@ -28,7 +28,7 @@
 
 static jint String_compareTo(JNIEnv* env, jobject javaThis, jobject javaRhs) {
   ScopedFastNativeObjectAccess soa(env);
-  if (UNLIKELY(javaRhs == NULL)) {
+  if (UNLIKELY(javaRhs == nullptr)) {
     ThrowNullPointerException("rhs == null");
     return -1;
   } else {
diff --git a/runtime/native/java_lang_Thread.cc b/runtime/native/java_lang_Thread.cc
index d3b52ba..be7022e 100644
--- a/runtime/native/java_lang_Thread.cc
+++ b/runtime/native/java_lang_Thread.cc
@@ -43,7 +43,7 @@
   ScopedFastNativeObjectAccess soa(env);
   MutexLock mu(soa.Self(), *Locks::thread_list_lock_);
   Thread* thread = Thread::FromManagedThread(soa, java_thread);
-  return (thread != NULL) ? thread->IsInterrupted() : JNI_FALSE;
+  return (thread != nullptr) ? thread->IsInterrupted() : JNI_FALSE;
 }
 
 static void Thread_nativeCreate(JNIEnv* env, jclass, jobject java_thread, jlong stack_size,
@@ -64,7 +64,7 @@
   ThreadState internal_thread_state = (has_been_started ? kTerminated : kStarting);
   MutexLock mu(soa.Self(), *Locks::thread_list_lock_);
   Thread* thread = Thread::FromManagedThread(soa, java_thread);
-  if (thread != NULL) {
+  if (thread != nullptr) {
     internal_thread_state = thread->GetState();
   }
   switch (internal_thread_state) {
@@ -99,7 +99,7 @@
 static jboolean Thread_nativeHoldsLock(JNIEnv* env, jobject java_thread, jobject java_object) {
   ScopedObjectAccess soa(env);
   mirror::Object* object = soa.Decode<mirror::Object*>(java_object);
-  if (object == NULL) {
+  if (object == nullptr) {
     ThrowNullPointerException("object == null");
     return JNI_FALSE;
   }
@@ -112,7 +112,7 @@
   ScopedFastNativeObjectAccess soa(env);
   MutexLock mu(soa.Self(), *Locks::thread_list_lock_);
   Thread* thread = Thread::FromManagedThread(soa, java_thread);
-  if (thread != NULL) {
+  if (thread != nullptr) {
     thread->Interrupt(soa.Self());
   }
 }
@@ -133,7 +133,7 @@
   bool timed_out;
   // Take suspend thread lock to avoid races with threads trying to suspend this one.
   Thread* thread = thread_list->SuspendThreadByPeer(peer, true, false, &timed_out);
-  if (thread != NULL) {
+  if (thread != nullptr) {
     {
       ScopedObjectAccess soa(env);
       thread->SetThreadName(name.c_str());
@@ -154,7 +154,7 @@
   ScopedObjectAccess soa(env);
   MutexLock mu(soa.Self(), *Locks::thread_list_lock_);
   Thread* thread = Thread::FromManagedThread(soa, java_thread);
-  if (thread != NULL) {
+  if (thread != nullptr) {
     thread->SetNativePriority(new_priority);
   }
 }
diff --git a/runtime/native/java_lang_reflect_Array.cc b/runtime/native/java_lang_reflect_Array.cc
index eddd7de..beb953b 100644
--- a/runtime/native/java_lang_reflect_Array.cc
+++ b/runtime/native/java_lang_reflect_Array.cc
@@ -27,13 +27,14 @@
 
 namespace art {
 
-static jobject Array_createMultiArray(JNIEnv* env, jclass, jclass javaElementClass, jobject javaDimArray) {
+static jobject Array_createMultiArray(
+    JNIEnv* env, jclass, jclass javaElementClass, jobject javaDimArray) {
   ScopedFastNativeObjectAccess soa(env);
-  DCHECK(javaElementClass != NULL);
+  DCHECK(javaElementClass != nullptr);
   StackHandleScope<2> hs(soa.Self());
   Handle<mirror::Class> element_class(hs.NewHandle(soa.Decode<mirror::Class*>(javaElementClass)));
   DCHECK(element_class->IsClass());
-  DCHECK(javaDimArray != NULL);
+  DCHECK(javaDimArray != nullptr);
   mirror::Object* dimensions_obj = soa.Decode<mirror::Object*>(javaDimArray);
   DCHECK(dimensions_obj->IsArrayInstance());
   DCHECK_EQ(dimensions_obj->GetClass()->GetComponentType()->GetPrimitiveType(),
@@ -47,18 +48,18 @@
 
 static jobject Array_createObjectArray(JNIEnv* env, jclass, jclass javaElementClass, jint length) {
   ScopedFastNativeObjectAccess soa(env);
-  DCHECK(javaElementClass != NULL);
+  DCHECK(javaElementClass != nullptr);
   if (UNLIKELY(length < 0)) {
     ThrowNegativeArraySizeException(length);
-    return NULL;
+    return nullptr;
   }
   mirror::Class* element_class = soa.Decode<mirror::Class*>(javaElementClass);
   Runtime* runtime = Runtime::Current();
   ClassLinker* class_linker = runtime->GetClassLinker();
   mirror::Class* array_class = class_linker->FindArrayClass(soa.Self(), &element_class);
-  if (UNLIKELY(array_class == NULL)) {
+  if (UNLIKELY(array_class == nullptr)) {
     CHECK(soa.Self()->IsExceptionPending());
-    return NULL;
+    return nullptr;
   }
   DCHECK(array_class->IsObjectArrayClass());
   mirror::Array* new_array = mirror::ObjectArray<mirror::Object*>::Alloc(
diff --git a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
index 987427e..b96ddc8 100644
--- a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
+++ b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
@@ -43,7 +43,7 @@
 
 /*
  * Get a stack trace as an array of StackTraceElement objects.  Returns
- * NULL on failure, e.g. if the threadId couldn't be found.
+ * nullptr on failure, e.g. if the threadId couldn't be found.
  */
 static jobjectArray DdmVmInternal_getStackTraceById(JNIEnv* env, jclass, jint thin_lock_id) {
   jobjectArray trace = nullptr;
@@ -145,7 +145,7 @@
   }
 
   jbyteArray result = env->NewByteArray(bytes.size());
-  if (result != NULL) {
+  if (result != nullptr) {
     env->SetByteArrayRegion(result, 0, bytes.size(), reinterpret_cast<const jbyte*>(&bytes[0]));
   }
   return result;