...and switch all NPE throwers over to the helper.
case U_UNSUPPORTED_ERROR:
return jniThrowException(env, "java/lang/UnsupportedOperationException", message);
default:
- return jniThrowException(env, "java/lang/RuntimeException", message);
+ return jniThrowRuntimeException(env, message);
}
}
#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;
}
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);
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)
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);
}
env->ReleaseStringUTFChars(nameStr, name);
} else {
- jniThrowException(env, "java/lang/NullPointerException", NULL);
+ jniThrowNullPointerException(env, NULL);
}
return valueStr;
}
} 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",
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);
jbyteArray javaAddress)
{
if (javaAddress == NULL) {
- jniThrowException(env, "java/lang/NullPointerException", NULL);
+ jniThrowNullPointerException(env, NULL);
return NULL;
}
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.)
static bool byteArrayToSocketAddress(JNIEnv *env,
jbyteArray addressBytes, int port, sockaddr_storage *sockaddress) {
if (addressBytes == NULL) {
- throwNullPointerException(env);
+ jniThrowNullPointerException(env, NULL);
return false;
}
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 =
static jstring osNetworkSystem_byteArrayToIpString(JNIEnv* env, jclass,
jbyteArray byteArray) {
if (byteArray == NULL) {
- throwNullPointerException(env);
+ jniThrowNullPointerException(env, NULL);
return NULL;
}
sockaddr_storage ss;
static jbyteArray osNetworkSystem_ipStringToByteArray(JNIEnv* env, jclass,
jstring javaString) {
if (javaString == NULL) {
- throwNullPointerException(env);
+ jniThrowNullPointerException(env, NULL);
return NULL;
}
static int createSocketFileDescriptor(JNIEnv* env, jobject fileDescriptor,
int type) {
if (fileDescriptor == NULL) {
- throwNullPointerException(env);
+ jniThrowNullPointerException(env, NULL);
errno = EBADF;
return -1;
}
// LOGD("ENTER acceptSocketImpl");
if (newSocket == NULL) {
- throwNullPointerException(env);
+ jniThrowNullPointerException(env, NULL);
return;
}
#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)
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.
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;
}
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;
}
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;
}
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;
}
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;
}
// LOGI("NativeCrypto_EVP_DigestFinal%x, %x, %d, %d", ctx, hash, offset);
if (ctx == NULL || hash == NULL) {
- throwNullPointerException(env);
+ jniThrowNullPointerException(env, NULL);
return -1;
}
// LOGI("NativeCrypto_EVP_DigestInit");
if (ctx == NULL || algorithm == NULL) {
- throwNullPointerException(env);
+ jniThrowNullPointerException(env, NULL);
return;
}
env->ReleaseStringUTFChars(algorithm, algorithmChars);
if (digest == NULL) {
- throwRuntimeException(env, "Hash algorithm not found");
+ jniThrowRuntimeException(env, "Hash algorithm not found");
return;
}
// LOGI("NativeCrypto_EVP_DigestSize");
if (ctx == NULL) {
- throwNullPointerException(env);
+ jniThrowNullPointerException(env, NULL);
return -1;
}
// LOGI("NativeCrypto_EVP_DigestBlockSize");
if (ctx == NULL) {
- throwNullPointerException(env);
+ jniThrowNullPointerException(env, NULL);
return -1;
}
// LOGI("NativeCrypto_EVP_DigestUpdate %x, %x, %d, %d", ctx, buffer, offset, length);
if (ctx == NULL || buffer == NULL) {
- throwNullPointerException(env);
+ jniThrowNullPointerException(env, NULL);
return;
}
// LOGI("NativeCrypto_EVP_VerifyInit");
if (ctx == NULL || algorithm == NULL) {
- throwNullPointerException(env);
+ jniThrowNullPointerException(env, NULL);
return;
}
env->ReleaseStringUTFChars(algorithm, algorithmChars);
if (digest == NULL) {
- throwRuntimeException(env, "Hash algorithm not found");
+ jniThrowRuntimeException(env, "Hash algorithm not found");
return;
}
// LOGI("NativeCrypto_EVP_VerifyUpdate %x, %x, %d, %d", ctx, buffer, offset, length);
if (ctx == NULL || buffer == NULL) {
- throwNullPointerException(env);
+ jniThrowNullPointerException(env, NULL);
return;
}
// 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;
}
}
/**
- * 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) {
// LOGD("Entering verifysignature()");
if (msg == NULL || sig == NULL || algorithm == NULL || mod == NULL || exp == NULL) {
- throwNullPointerException(env);
+ jniThrowNullPointerException(env, NULL);
return -1;
}
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();
}
}
/*
+ * 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)
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.
{
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);