Fix jniThrowRuntimeException for C callers, add jniThrowNullPointerException.

...and switch all NPE throwers over to the helper.
diff --git a/libcore/icu/src/main/native/ErrorCode.cpp b/libcore/icu/src/main/native/ErrorCode.cpp
index 94c4239..a9d0691 100644
--- a/libcore/icu/src/main/native/ErrorCode.cpp
+++ b/libcore/icu/src/main/native/ErrorCode.cpp
@@ -34,6 +34,6 @@
     case U_UNSUPPORTED_ERROR:
         return jniThrowException(env, "java/lang/UnsupportedOperationException", message);
     default:
-        return jniThrowException(env, "java/lang/RuntimeException", message);
+        return jniThrowRuntimeException(env, message);
     }
 }
diff --git a/libcore/icu/src/main/native/NativeDecimalFormat.cpp b/libcore/icu/src/main/native/NativeDecimalFormat.cpp
index ba62726..9170f27 100644
--- a/libcore/icu/src/main/native/NativeDecimalFormat.cpp
+++ b/libcore/icu/src/main/native/NativeDecimalFormat.cpp
@@ -29,18 +29,13 @@
 #include <stdlib.h>
 #include <string.h>
 
-// FIXME: move to JNIHelp.h
-static void jniThrowNullPointerException(JNIEnv* env) {
-    jniThrowException(env, "java/lang/NullPointerException", NULL);
-}
-
 static DecimalFormat* toDecimalFormat(jint addr) {
     return reinterpret_cast<DecimalFormat*>(static_cast<uintptr_t>(addr));
 }
 
 static jint openDecimalFormatImpl(JNIEnv* env, jclass clazz, jstring pattern0) {
     if (pattern0 == NULL) {
-        jniThrowNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return 0;
     }
 
@@ -218,7 +213,7 @@
 
 static void applyPatternImpl(JNIEnv *env, jclass clazz, jint addr, jboolean localized, jstring pattern0) {
     if (pattern0 == NULL) {
-        jniThrowNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return;
     }
     ScopedJavaUnicodeString pattern(env, pattern0);
diff --git a/libcore/icu/src/main/native/NativeRegEx.cpp b/libcore/icu/src/main/native/NativeRegEx.cpp
index 387d7e4..7b3cafc 100644
--- a/libcore/icu/src/main/native/NativeRegEx.cpp
+++ b/libcore/icu/src/main/native/NativeRegEx.cpp
@@ -54,9 +54,8 @@
     env->Throw(except);
 }
 
-static void throwRuntimeException(JNIEnv* env, UErrorCode status)
-{
-    jniThrowException(env, "java/lang/RuntimeException", u_errorName(status));
+static void throwRuntimeException(JNIEnv* env, UErrorCode status) {
+    jniThrowRuntimeException(env, u_errorName(status));
 }
 
 static void _close(JNIEnv* env, jclass clazz, RegExData* data)
diff --git a/libcore/icu/src/main/native/UCharacter.cpp b/libcore/icu/src/main/native/UCharacter.cpp
index c13b6d3..3fd8151 100644
--- a/libcore/icu/src/main/native/UCharacter.cpp
+++ b/libcore/icu/src/main/native/UCharacter.cpp
@@ -138,7 +138,7 @@
 
 static int forNameImpl(JNIEnv* env, jclass, jstring blockName) {
     if (blockName == NULL) {
-        jniThrowException(env, "java/lang/NullPointerException", NULL);
+        jniThrowNullPointerException(env, NULL);
         return -1;
     }
     const char* bName = env->GetStringUTFChars(blockName, NULL);
diff --git a/libcore/luni-kernel/src/main/native/java_lang_System.cpp b/libcore/luni-kernel/src/main/native/java_lang_System.cpp
index d02481c..52150d3 100644
--- a/libcore/luni-kernel/src/main/native/java_lang_System.cpp
+++ b/libcore/luni-kernel/src/main/native/java_lang_System.cpp
@@ -38,7 +38,7 @@
         }
         env->ReleaseStringUTFChars(nameStr, name);
     } else {
-        jniThrowException(env, "java/lang/NullPointerException", NULL);
+        jniThrowNullPointerException(env, NULL);
     }
 
     return valueStr;
diff --git a/libcore/luni/src/main/native/java_net_InetAddress.cpp b/libcore/luni/src/main/native/java_net_InetAddress.cpp
index 63053a8..04c18af 100644
--- a/libcore/luni/src/main/native/java_net_InetAddress.cpp
+++ b/libcore/luni/src/main/native/java_net_InetAddress.cpp
@@ -143,8 +143,7 @@
         }
     } else if (result == EAI_SYSTEM && errno == EACCES) {
         /* No permission to use network */
-        jniThrowException(
-            env, "java/lang/SecurityException",
+        jniThrowException(env, "java/lang/SecurityException",
             "Permission denied (maybe missing INTERNET permission)");
     } else {
         jniThrowException(env, "java/net/UnknownHostException",
@@ -160,7 +159,7 @@
 
 jobjectArray InetAddress_getaddrinfo(JNIEnv* env, jobject obj, jstring javaName) {
     if (javaName == NULL) {
-        jniThrowException(env, "java/lang/NullPointerException", NULL);
+        jniThrowNullPointerException(env, NULL);
         return NULL;
     }
     const char* name = env->GetStringUTFChars(javaName, NULL);
@@ -182,7 +181,7 @@
                                          jbyteArray javaAddress)
 {
     if (javaAddress == NULL) {
-        jniThrowException(env, "java/lang/NullPointerException", NULL);
+        jniThrowNullPointerException(env, NULL);
         return NULL;
     }
 
diff --git a/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp b/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
index 07eb381..12c3dd9 100644
--- a/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
+++ b/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
@@ -227,11 +227,6 @@
     jniThrowExceptionWithErrno(env, "java/net/SocketTimeoutException", error);
 }
 
-// TODO(enh): move to JNIHelp.h
-static void throwNullPointerException(JNIEnv *env) {
-    jniThrowException(env, "java/lang/NullPointerException", NULL);
-}
-
 // Used by functions that shouldn't throw SocketException. (These functions
 // aren't meant to see bad addresses, so seeing one really does imply an
 // internal error.)
@@ -377,7 +372,7 @@
 static bool byteArrayToSocketAddress(JNIEnv *env,
         jbyteArray addressBytes, int port, sockaddr_storage *sockaddress) {
     if (addressBytes == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return false;
     }
 
@@ -412,7 +407,7 @@
         int port, sockaddr_storage *sockaddress) {
     // Get the byte array that stores the IP address bytes in the InetAddress.
     if (inetaddress == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return false;
     }
     jbyteArray addressBytes =
@@ -432,7 +427,7 @@
 static jstring osNetworkSystem_byteArrayToIpString(JNIEnv* env, jclass,
         jbyteArray byteArray) {
     if (byteArray == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return NULL;
     }
     sockaddr_storage ss;
@@ -486,7 +481,7 @@
 static jbyteArray osNetworkSystem_ipStringToByteArray(JNIEnv* env, jclass,
         jstring javaString) {
     if (javaString == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return NULL;
     }
 
@@ -1442,7 +1437,7 @@
 static int createSocketFileDescriptor(JNIEnv* env, jobject fileDescriptor,
                                       int type) {
     if (fileDescriptor == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         errno = EBADF;
         return -1;
     }
@@ -1843,7 +1838,7 @@
     // LOGD("ENTER acceptSocketImpl");
 
     if (newSocket == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return;
     }
 
diff --git a/libcore/openssl/src/main/native/BNInterface.c b/libcore/openssl/src/main/native/BNInterface.c
index 79f0680..ff2a2ae 100644
--- a/libcore/openssl/src/main/native/BNInterface.c
+++ b/libcore/openssl/src/main/native/BNInterface.c
@@ -31,20 +31,12 @@
 #define TRUE 1
 #endif
 
-
-static void
-throwNewNullPointerException (JNIEnv* env, const char* message)
-{
-    jniThrowException(env, "java/lang/NullPointerException", message);
-}
-
-static int isValidHandle (JNIEnv* env, void* handle, const char *message)
-{
+static int isValidHandle (JNIEnv* env, void* handle, const char *message) {
     if (handle == NULL) {
-        throwNewNullPointerException(env, message);
+        jniThrowNullPointerException(env, message);
         return FALSE;
     }
-    else return TRUE;
+    return TRUE;
 }
 
 static int oneValidHandle (JNIEnv* env, void* a)
diff --git a/libcore/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp b/libcore/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp
index c6d23e7..69ab7fe 100644
--- a/libcore/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp
+++ b/libcore/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp
@@ -40,20 +40,6 @@
     ERR_remove_state(0);
 }
 
-/**
- * Throws a NullPointerException without any message.
- */
-static void throwNullPointerException(JNIEnv* env) {
-    jniThrowException(env, "java/lang/NullPointerException", NULL);
-}
-
-/**
- * Throws a RuntimeException with a human-readable error message.
- */
-static void throwRuntimeException(JNIEnv* env, const char* message) {
-    jniThrowException(env, "java/lang/RuntimeException", message);
-}
-
 /*
  * Checks this thread's OpenSSL error queue and throws a RuntimeException if
  * necessary.
@@ -68,7 +54,7 @@
         char message[50];
         ERR_error_string_n(error, message, sizeof(message));
         LOGD("OpenSSL error %d: %s", error, message);
-        throwRuntimeException(env, message);
+        jniThrowRuntimeException(env, message);
         result = 1;
     }
 
@@ -105,7 +91,7 @@
     
     if (rsa->n == NULL || rsa->e == NULL) {
         rsaDestroyKey(env, clazz, rsa);
-        throwRuntimeException(env, "Unable to convert BigInteger to BIGNUM");
+        jniThrowRuntimeException(env, "Unable to convert BigInteger to BIGNUM");
         return NULL;
     }
     
@@ -131,7 +117,7 @@
     
     if (rsa->n == NULL || rsa->e == NULL || rsa->d == NULL || rsa->p == NULL || rsa->q == NULL) {
         rsaDestroyKey(env, clazz, rsa);
-        throwRuntimeException(env, "Unable to convert BigInteger to BIGNUM");
+        jniThrowRuntimeException(env, "Unable to convert BigInteger to BIGNUM");
         return NULL;
     }
     
@@ -168,7 +154,7 @@
 
     if (dsa->p == NULL || dsa->q == NULL || dsa->g == NULL || dsa->pub_key == NULL) {
         DSA_free(dsa);
-        throwRuntimeException(env, "Unable to convert BigInteger to BIGNUM");
+        jniThrowRuntimeException(env, "Unable to convert BigInteger to BIGNUM");
         return NULL;
     }
     
@@ -206,7 +192,7 @@
     
     if (rsa->n == NULL || rsa->e == NULL) {
         RSA_free(rsa);
-        throwRuntimeException(env, "Unable to convert BigInteger to BIGNUM");
+        jniThrowRuntimeException(env, "Unable to convert BigInteger to BIGNUM");
         return NULL;
     }
     
@@ -254,7 +240,7 @@
     // LOGI("NativeCrypto_EVP_DigestFinal%x, %x, %d, %d", ctx, hash, offset);
     
     if (ctx == NULL || hash == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return -1;
     }
 
@@ -276,7 +262,7 @@
     // LOGI("NativeCrypto_EVP_DigestInit");
     
     if (ctx == NULL || algorithm == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return;
     }
     
@@ -286,7 +272,7 @@
     env->ReleaseStringUTFChars(algorithm, algorithmChars);
     
     if (digest == NULL) {
-        throwRuntimeException(env, "Hash algorithm not found");
+        jniThrowRuntimeException(env, "Hash algorithm not found");
         return;
     }
     
@@ -302,7 +288,7 @@
     // LOGI("NativeCrypto_EVP_DigestSize");
     
     if (ctx == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return -1;
     }
     
@@ -320,7 +306,7 @@
     // LOGI("NativeCrypto_EVP_DigestBlockSize");
     
     if (ctx == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return -1;
     }
     
@@ -338,7 +324,7 @@
     // LOGI("NativeCrypto_EVP_DigestUpdate %x, %x, %d, %d", ctx, buffer, offset, length);
     
     if (ctx == NULL || buffer == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return;
     }
   
@@ -356,7 +342,7 @@
     // LOGI("NativeCrypto_EVP_VerifyInit");
     
     if (ctx == NULL || algorithm == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return;
     }
     
@@ -366,7 +352,7 @@
     env->ReleaseStringUTFChars(algorithm, algorithmChars);
     
     if (digest == NULL) {
-        throwRuntimeException(env, "Hash algorithm not found");
+        jniThrowRuntimeException(env, "Hash algorithm not found");
         return;
     }
     
@@ -382,7 +368,7 @@
     // LOGI("NativeCrypto_EVP_VerifyUpdate %x, %x, %d, %d", ctx, buffer, offset, length);
     
     if (ctx == NULL || buffer == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return;
     }
   
@@ -400,7 +386,7 @@
     // LOGI("NativeCrypto_EVP_VerifyFinal %x, %x, %d, %d %x", ctx, buffer, offset, length, pkey);
     
     if (ctx == NULL || buffer == NULL || pkey == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return -1;
     }
   
diff --git a/libcore/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl.cpp b/libcore/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl.cpp
index 646ae97..a3c86d6 100644
--- a/libcore/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl.cpp
+++ b/libcore/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl.cpp
@@ -64,24 +64,6 @@
 }
 
 /**
- * Throws a NullPointerException without any message.
- */
-static void throwNullPointerException(JNIEnv* env) {
-    if (jniThrowException(env, "java/lang/NullPointerException", NULL)) {
-        LOGE("Unable to throw");
-    }
-}
-
-/**
- * Throws a RuntimeException with a human-readable error message.
- */
-static void throwRuntimeException(JNIEnv* env, const char* message) {
-    if (jniThrowException(env, "java/lang/RuntimeException", message)) {
-        LOGE("Unable to throw");
-    }
-}
-
-/**
  * Throws an SocketTimeoutException with the given string as a message.
  */
 static void throwSocketTimeoutException(JNIEnv* env, const char* message) {
@@ -1770,7 +1752,7 @@
     // LOGD("Entering verifysignature()");
 
     if (msg == NULL || sig == NULL || algorithm == NULL || mod == NULL || exp == NULL) {
-        throwNullPointerException(env);
+        jniThrowNullPointerException(env, NULL);
         return -1;
     }
 
@@ -1809,9 +1791,9 @@
         if (error != 0) {
             char message[50];
             ERR_error_string_n(error, message, sizeof(message));
-            throwRuntimeException(env, message);
+            jniThrowRuntimeException(env, message);
         } else {
-            throwRuntimeException(env, "Internal error during verification");
+            jniThrowRuntimeException(env, "Internal error during verification");
         }
         freeSslErrorState();
     }
diff --git a/libnativehelper/JNIHelp.c b/libnativehelper/JNIHelp.c
index d0e2f89..a75b837 100644
--- a/libnativehelper/JNIHelp.c
+++ b/libnativehelper/JNIHelp.c
@@ -133,6 +133,14 @@
 }
 
 /*
+ * Throw a java.lang.NullPointerException, with an optional message.
+ */
+int jniThrowNullPointerException(JNIEnv* env, const char* msg)
+{
+    return jniThrowException(env, "java/lang/NullPointerException", msg);
+}
+
+/*
  * Throw a java.lang.RuntimeException, with an optional message.
  */
 int jniThrowRuntimeException(JNIEnv* env, const char* msg)
diff --git a/libnativehelper/include/nativehelper/JNIHelp.h b/libnativehelper/include/nativehelper/JNIHelp.h
index 3d8983f..59c2620 100644
--- a/libnativehelper/include/nativehelper/JNIHelp.h
+++ b/libnativehelper/include/nativehelper/JNIHelp.h
@@ -54,9 +54,14 @@
 int jniThrowException(C_JNIEnv* env, const char* className, const char* msg);
 
 /*
+ * Throw a java.lang.NullPointerException, with an optional message.
+ */
+int jniThrowNullPointerException(C_JNIEnv* env, const char* msg);
+
+/*
  * Throw a java.lang.RuntimeException, with an optional message.
  */
-int jniThrowRuntimeException(JNIEnv* env, const char* msg);
+int jniThrowRuntimeException(C_JNIEnv* env, const char* msg);
 
 /*
  * Throw a java.io.IOException, generating the message from errno.
@@ -107,6 +112,14 @@
 {
     return jniThrowException(&env->functions, className, msg);
 }
+inline int jniThrowNullPointerException(JNIEnv* env, const char* msg)
+{
+    return jniThrowNullPointerException(&env->functions, msg);
+}
+inline int jniThrowRuntimeException(JNIEnv* env, const char* msg)
+{
+    return jniThrowRuntimeException(&env->functions, msg);
+}
 inline int jniThrowIOException(JNIEnv* env, int errnum)
 {
     return jniThrowIOException(&env->functions, errnum);