diff options
10 files changed, 37 insertions, 89 deletions
diff --git a/icu/src/main/native/ErrorCode.cpp b/icu/src/main/native/ErrorCode.cpp index 94c4239..a9d0691 100644 --- a/icu/src/main/native/ErrorCode.cpp +++ b/icu/src/main/native/ErrorCode.cpp @@ -34,6 +34,6 @@ UBool icu4jni_error(JNIEnv *env, UErrorCode errorCode) 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/icu/src/main/native/NativeDecimalFormat.cpp b/icu/src/main/native/NativeDecimalFormat.cpp index ba62726..9170f27 100644 --- a/icu/src/main/native/NativeDecimalFormat.cpp +++ b/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 jstring getTextAttribute(JNIEnv *env, jclass clazz, jint addr, 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/icu/src/main/native/NativeRegEx.cpp b/icu/src/main/native/NativeRegEx.cpp index 387d7e4..7b3cafc 100644 --- a/icu/src/main/native/NativeRegEx.cpp +++ b/icu/src/main/native/NativeRegEx.cpp @@ -54,9 +54,8 @@ static void throwPatternSyntaxException(JNIEnv* env, UErrorCode status, 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/icu/src/main/native/UCharacter.cpp b/icu/src/main/native/UCharacter.cpp index c13b6d3..3fd8151 100644 --- a/icu/src/main/native/UCharacter.cpp +++ b/icu/src/main/native/UCharacter.cpp @@ -138,7 +138,7 @@ static jboolean isLowerCaseImpl(JNIEnv*, jclass, jint codePoint) { 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/luni-kernel/src/main/native/java_lang_System.cpp b/luni-kernel/src/main/native/java_lang_System.cpp index d02481c..52150d3 100644 --- a/luni-kernel/src/main/native/java_lang_System.cpp +++ b/luni-kernel/src/main/native/java_lang_System.cpp @@ -38,7 +38,7 @@ static jstring java_getEnvByName(JNIEnv* env, jclass, jstring nameStr) { } env->ReleaseStringUTFChars(nameStr, name); } else { - jniThrowException(env, "java/lang/NullPointerException", NULL); + jniThrowNullPointerException(env, NULL); } return valueStr; diff --git a/luni/src/main/native/java_net_InetAddress.cpp b/luni/src/main/native/java_net_InetAddress.cpp index 63053a8..04c18af 100644 --- a/luni/src/main/native/java_net_InetAddress.cpp +++ b/luni/src/main/native/java_net_InetAddress.cpp @@ -143,8 +143,7 @@ static jobjectArray InetAddress_getaddrinfoImpl(JNIEnv* env, const char* name) { } } 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 @@ static jobjectArray InetAddress_getaddrinfoImpl(JNIEnv* env, const char* name) { 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 @@ static jstring InetAddress_getnameinfo(JNIEnv* env, jobject obj, jbyteArray javaAddress) { if (javaAddress == NULL) { - jniThrowException(env, "java/lang/NullPointerException", NULL); + jniThrowNullPointerException(env, NULL); return NULL; } diff --git a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp index 07eb381..12c3dd9 100644 --- a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp +++ b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp @@ -227,11 +227,6 @@ static void jniThrowSocketTimeoutException(JNIEnv* env, int error) { 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 const sockaddr* convertIpv4ToMapped(int fd, 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 @@ static bool inetAddressToSocketAddress(JNIEnv *env, jobject inetaddress, 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 bool inetAddressToSocketAddress(JNIEnv *env, jobject inetaddress, 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 jstring osNetworkSystem_byteArrayToIpString(JNIEnv* env, jclass, static jbyteArray osNetworkSystem_ipStringToByteArray(JNIEnv* env, jclass, jstring javaString) { if (javaString == NULL) { - throwNullPointerException(env); + jniThrowNullPointerException(env, NULL); return NULL; } @@ -1442,7 +1437,7 @@ static bool initCachedFields(JNIEnv* env) { 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 @@ static void osNetworkSystem_acceptSocketImpl(JNIEnv* env, jclass, // LOGD("ENTER acceptSocketImpl"); if (newSocket == NULL) { - throwNullPointerException(env); + jniThrowNullPointerException(env, NULL); return; } diff --git a/openssl/src/main/native/BNInterface.c b/openssl/src/main/native/BNInterface.c index 79f0680..ff2a2ae 100644 --- a/openssl/src/main/native/BNInterface.c +++ b/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/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp b/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp index c6d23e7..69ab7fe 100644 --- a/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp +++ b/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp @@ -40,20 +40,6 @@ static void freeSslErrorState(void) { 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 @@ static int throwExceptionIfNecessary(JNIEnv* env) { 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 @@ static RSA* rsaCreatePublicKey(JNIEnv* env, jclass clazz, jbyteArray n, jbyteArr 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 @@ static RSA* rsaCreatePrivateKey(JNIEnv* env, jclass clazz, jbyteArray n, jbyteAr 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 @@ static EVP_PKEY* NativeCrypto_EVP_PKEY_new_DSA(JNIEnv* env, jclass clazz, jbyteA 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 @@ static EVP_PKEY* NativeCrypto_EVP_PKEY_new_RSA(JNIEnv* env, jclass clazz, jbyteA 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 @@ static jint NativeCrypto_EVP_DigestFinal(JNIEnv* env, jclass clazz, EVP_MD_CTX* // 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 @@ static void NativeCrypto_EVP_DigestInit(JNIEnv* env, jclass clazz, EVP_MD_CTX* c // LOGI("NativeCrypto_EVP_DigestInit"); if (ctx == NULL || algorithm == NULL) { - throwNullPointerException(env); + jniThrowNullPointerException(env, NULL); return; } @@ -286,7 +272,7 @@ static void NativeCrypto_EVP_DigestInit(JNIEnv* env, jclass clazz, EVP_MD_CTX* c env->ReleaseStringUTFChars(algorithm, algorithmChars); if (digest == NULL) { - throwRuntimeException(env, "Hash algorithm not found"); + jniThrowRuntimeException(env, "Hash algorithm not found"); return; } @@ -302,7 +288,7 @@ static jint NativeCrypto_EVP_DigestSize(JNIEnv* env, jclass clazz, EVP_MD_CTX* c // LOGI("NativeCrypto_EVP_DigestSize"); if (ctx == NULL) { - throwNullPointerException(env); + jniThrowNullPointerException(env, NULL); return -1; } @@ -320,7 +306,7 @@ static jint NativeCrypto_EVP_DigestBlockSize(JNIEnv* env, jclass clazz, EVP_MD_C // LOGI("NativeCrypto_EVP_DigestBlockSize"); if (ctx == NULL) { - throwNullPointerException(env); + jniThrowNullPointerException(env, NULL); return -1; } @@ -338,7 +324,7 @@ static void NativeCrypto_EVP_DigestUpdate(JNIEnv* env, jclass clazz, EVP_MD_CTX* // 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 @@ static void NativeCrypto_EVP_VerifyInit(JNIEnv* env, jclass clazz, EVP_MD_CTX* c // LOGI("NativeCrypto_EVP_VerifyInit"); if (ctx == NULL || algorithm == NULL) { - throwNullPointerException(env); + jniThrowNullPointerException(env, NULL); return; } @@ -366,7 +352,7 @@ static void NativeCrypto_EVP_VerifyInit(JNIEnv* env, jclass clazz, EVP_MD_CTX* c env->ReleaseStringUTFChars(algorithm, algorithmChars); if (digest == NULL) { - throwRuntimeException(env, "Hash algorithm not found"); + jniThrowRuntimeException(env, "Hash algorithm not found"); return; } @@ -382,7 +368,7 @@ static void NativeCrypto_EVP_VerifyUpdate(JNIEnv* env, jclass clazz, EVP_MD_CTX* // 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 @@ static int NativeCrypto_EVP_VerifyFinal(JNIEnv* env, jclass clazz, EVP_MD_CTX* c // 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/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl.cpp b/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl.cpp index 646ae97..a3c86d6 100644 --- a/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl.cpp +++ b/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl.cpp @@ -64,24 +64,6 @@ static BIO *stringToMemBuf(JNIEnv* env, jstring string) { } /** - * 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 @@ static int org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl_verifysignatu // 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 @@ static int org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl_verifysignatu 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(); } |