summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--icu/src/main/native/ErrorCode.c62
-rw-r--r--luni/src/main/native/java_net_InetAddress.cpp17
-rw-r--r--luni/src/main/native/java_net_NetworkInterface.c24
-rw-r--r--sql/src/main/native/sqlite_jni.c23
-rw-r--r--x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLServerSocketImpl.cpp20
-rw-r--r--x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl.cpp4
-rw-r--r--xml/src/main/native/org_apache_harmony_xml_ExpatParser.cpp24
7 files changed, 44 insertions, 130 deletions
diff --git a/icu/src/main/native/ErrorCode.c b/icu/src/main/native/ErrorCode.c
index b3e43cd..94c4239 100644
--- a/icu/src/main/native/ErrorCode.c
+++ b/icu/src/main/native/ErrorCode.c
@@ -8,50 +8,32 @@
*/
#include "ErrorCode.h"
-
-/* private data members ----------------------------------------------------*/
-
-/**
-* Name of the java runtime exception classes
-*/
-#define ILLEGALARGUMENTEXCEPTION_ "java/lang/IllegalArgumentException"
-#define ARRAYINDEXOUTOFBOUNDSEXCEPTION_ "java/lang/ArrayIndexOutOfBoundsException"
-#define UNSUPPORTEDOPERATIONEXCEPTION_ "java/lang/UnsupportedOperationException"
-#define RUNTIMEEXCEPTION_ "java/lang/RuntimeException"
-
-/* public methods ---------------------------------------------------------*/
+#include "JNIHelp.h"
/**
-* Checks if an error has occured.
-* Throws a generic Java RuntimeException if an error has occured.
-* @param env JNI environment variable
-* @param errorcode code to determine if it is an erro
-* @return 0 if errorcode is not an error, 1 if errorcode is an error, but the
+* Checks if an error has occurred, throwing a suitable exception if so.
+* @param env JNI environment
+* @param errorCode code to determine if it is an error
+* @return 0 if errorCode is not an error, 1 if errorCode is an error, but the
* creation of the exception to be thrown fails
-* @exception thrown if errorcode represents an error
+ * @exception thrown if errorCode represents an error
*/
-UBool icu4jni_error(JNIEnv *env, UErrorCode errorcode)
+UBool icu4jni_error(JNIEnv *env, UErrorCode errorCode)
{
- const char *emsg = u_errorName(errorcode);
- jclass exception;
-
- if (errorcode > U_ZERO_ERROR && errorcode < U_ERROR_LIMIT) {
- switch (errorcode) {
- case U_ILLEGAL_ARGUMENT_ERROR :
- exception = (*env)->FindClass(env, ILLEGALARGUMENTEXCEPTION_);
- break;
- case U_INDEX_OUTOFBOUNDS_ERROR :
- case U_BUFFER_OVERFLOW_ERROR :
- exception = (*env)->FindClass(env, ARRAYINDEXOUTOFBOUNDSEXCEPTION_);
- break;
- case U_UNSUPPORTED_ERROR :
- exception = (*env)->FindClass(env, UNSUPPORTEDOPERATIONEXCEPTION_);
- break;
- default :
- exception = (*env)->FindClass(env, RUNTIMEEXCEPTION_);
+ const char* message = u_errorName(errorCode);
+ if (errorCode <= U_ZERO_ERROR || errorCode >= U_ERROR_LIMIT) {
+ return 0;
+ }
+
+ switch (errorCode) {
+ case U_ILLEGAL_ARGUMENT_ERROR:
+ return jniThrowException(env, "java/lang/IllegalArgumentException", message);
+ case U_INDEX_OUTOFBOUNDS_ERROR:
+ case U_BUFFER_OVERFLOW_ERROR:
+ return jniThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", message);
+ case U_UNSUPPORTED_ERROR:
+ return jniThrowException(env, "java/lang/UnsupportedOperationException", message);
+ default:
+ return jniThrowException(env, "java/lang/RuntimeException", message);
}
-
- return ((*env)->ThrowNew(env, exception, emsg) != 0);
- }
- return 0;
}
diff --git a/luni/src/main/native/java_net_InetAddress.cpp b/luni/src/main/native/java_net_InetAddress.cpp
index 243b63d..4e58a1f 100644
--- a/luni/src/main/native/java_net_InetAddress.cpp
+++ b/luni/src/main/native/java_net_InetAddress.cpp
@@ -47,19 +47,6 @@ static jstring InetAddress_gethostname(JNIEnv* env, jobject obj)
}
}
-static void throwNullPointerException(JNIEnv* env)
-{
- const char* className = "java/lang/NullPointerException";
-
- jclass exClass = env->FindClass(className);
-
- if (exClass == NULL) {
- LOGE("Unable to find class %s", className);
- } else {
- env->ThrowNew(exClass, NULL);
- }
-}
-
#if LOG_DNS
static void logIpString(struct addrinfo* ai, const char* name)
{
@@ -207,7 +194,7 @@ jobjectArray InetAddress_getallbyname(JNIEnv* env, jobject obj,
jboolean preferIPv4Stack)
{
if (javaName == NULL) {
- throwNullPointerException(env);
+ jniThrowException(env, "java/lang/NullPointerException", NULL);
return NULL;
}
@@ -246,7 +233,7 @@ static jstring InetAddress_gethostbyaddr(JNIEnv* env, jobject obj,
jbyteArray javaAddress)
{
if (javaAddress == NULL) {
- throwNullPointerException(env);
+ jniThrowException(env, "java/lang/NullPointerException", NULL);
return NULL;
}
diff --git a/luni/src/main/native/java_net_NetworkInterface.c b/luni/src/main/native/java_net_NetworkInterface.c
index c659ae1..7fdf4fe 100644
--- a/luni/src/main/native/java_net_NetworkInterface.c
+++ b/luni/src/main/native/java_net_NetworkInterface.c
@@ -34,27 +34,7 @@
* Throws an IOException with the given message.
*/
static void throwSocketException(JNIEnv *env, const char *message) {
- jclass exClass = (*env)->FindClass(env, "java/net/SocketException");
-
- if(exClass == NULL) {
- LOGE("Unable to find class java/net/SocketException");
- } else {
- (*env)->ThrowNew(env, exClass, message);
- }
-}
-
-
-/**
- * Throws a NullPointerException.
- */
-static void throwNullPointerException(JNIEnv *env) {
- jclass exClass = (*env)->FindClass(env, "java/lang/NullPointerException");
-
- if(exClass == NULL) {
- LOGE("Unable to find class java/lang/NullPointerException");
- } else {
- (*env)->ThrowNew(env, exClass, NULL);
- }
+ jniThrowException(env, "java/net/SocketException", message);
}
/**
@@ -242,7 +222,7 @@ static int structInToJavaAddress(
JNIEnv *env, struct in_addr *address, jbyteArray java_address) {
if (java_address == NULL) {
- throwNullPointerException(env);
+ jniThrowException(env, "java/lang/NullPointerException", NULL);
return -1;
}
diff --git a/sql/src/main/native/sqlite_jni.c b/sql/src/main/native/sqlite_jni.c
index 82aa8a0..1a23769 100644
--- a/sql/src/main/native/sqlite_jni.c
+++ b/sql/src/main/native/sqlite_jni.c
@@ -1,3 +1,5 @@
+#include "JNIHelp.h"
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -276,23 +278,13 @@ freep(char **strp)
static void
throwex(JNIEnv *env, const char *msg)
{
- jclass except = (*env)->FindClass(env, "SQLite/Exception");
-
- (*env)->ExceptionClear(env);
- if (except) {
- (*env)->ThrowNew(env, except, msg);
- }
+ jniThrowException(env, "SQLite/Exception", msg);
}
static void
throwoom(JNIEnv *env, const char *msg)
{
- jclass except = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
-
- (*env)->ExceptionClear(env);
- if (except) {
- (*env)->ThrowNew(env, except, msg);
- }
+ jniThrowException(env, "java/lang/OutOfMemoryError", msg);
}
static void
@@ -305,12 +297,7 @@ throwclosed(JNIEnv *env)
static void
throwioex(JNIEnv *env, const char *msg)
{
- jclass except = (*env)->FindClass(env, "java/io/IOException");
-
- (*env)->ExceptionClear(env);
- if (except) {
- (*env)->ThrowNew(env, except, msg);
- }
+ jniThrowException(env, "java/io/IOException", msg);
}
#endif
diff --git a/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLServerSocketImpl.cpp b/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLServerSocketImpl.cpp
index bb5e3b7..2a55bbc 100644
--- a/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLServerSocketImpl.cpp
+++ b/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLServerSocketImpl.cpp
@@ -41,20 +41,10 @@
static jfieldID field_ssl_ctx;
/**
- * Throws java.io.IOexception with the provided message.
+ * Throws java.io.IOException with the provided message.
*/
-static void throwIOExceptionStr(JNIEnv* env, const char* message)
-{
- jclass exClass = env->FindClass("java/io/IOException");
-
- if (exClass == NULL)
- {
- LOGE("Unable to find class java/io/IOException");
- }
- else
- {
- env->ThrowNew(exClass, message);
- }
+static void throwIOExceptionStr(JNIEnv* env, const char* message) {
+ jniThrowException(env, "java/io/IOException", message);
}
/**
@@ -251,8 +241,8 @@ static void org_apache_harmony_xnet_provider_jsse_OpenSSLServerSocketImpl_setena
ret = SSL_CTX_set_cipher_list(ctx, str);
if(ret == 0) {
- jclass exClass = env->FindClass("java/lang/IllegalArgumentException");
- env->ThrowNew(exClass, "Illegal cipher suite strings.");
+ jniThrowException(env, "java/lang/IllegalArgumentException",
+ "Illegal cipher suite strings.");
}
}
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 1b0feeb..2e1adb1 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
@@ -1500,8 +1500,8 @@ static void org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl_setenabledci
if (ret == 0) {
freeSslErrorState();
- jclass exClass = env->FindClass("java/lang/IllegalArgumentException");
- env->ThrowNew(exClass, "Illegal cipher suite strings.");
+ jniThrowException(env, "java/lang/IllegalArgumentException",
+ "Illegal cipher suite strings.");
}
}
diff --git a/xml/src/main/native/org_apache_harmony_xml_ExpatParser.cpp b/xml/src/main/native/org_apache_harmony_xml_ExpatParser.cpp
index 6132107..15f1d28 100644
--- a/xml/src/main/native/org_apache_harmony_xml_ExpatParser.cpp
+++ b/xml/src/main/native/org_apache_harmony_xml_ExpatParser.cpp
@@ -327,15 +327,9 @@ static jstring internStringOfLength(JNIEnv* env, ParsingContext* parsingContext,
return internString(env, parsingContext, nullTerminated);
}
-/**
- * Throw an assertion error.
- *
- * @param message to show
- */
-static void fail(JNIEnv* env, const char* message) {
- jclass clazz;
- clazz = env->FindClass("java/lang/AssertionError");
- env->ThrowNew(clazz, message);
+static void jniThrowExpatException(JNIEnv* env, XML_Error error) {
+ const char* message = XML_ErrorString(error);
+ jniThrowException(env, "org/apache/harmony/xml/ExpatException", message);
}
/**
@@ -1001,9 +995,7 @@ static void appendString(JNIEnv* env, jobject object, jint pointer, jstring xml,
if (!XML_Parse(parser, (char*) characters, length, isFinal)
&& !env->ExceptionCheck()) {
- jclass clazz = env->FindClass("org/apache/harmony/xml/ExpatException");
- const char* errorMessage = XML_ErrorString(XML_GetErrorCode(parser));
- env->ThrowNew(clazz, errorMessage);
+ jniThrowExpatException(env, XML_GetErrorCode(parser));
}
// We have to temporarily clear an exception before we can release local
@@ -1041,9 +1033,7 @@ static void appendCharacters(JNIEnv* env, jobject object, jint pointer,
if (!XML_Parse(parser, ((char*) characters) + (offset << 1),
length << 1, XML_FALSE) && !env->ExceptionCheck()) {
- jclass clazz = env->FindClass("org/apache/harmony/xml/ExpatException");
- const char* errorMessage = XML_ErrorString(XML_GetErrorCode(parser));
- env->ThrowNew(clazz, errorMessage);
+ jniThrowExpatException(env, XML_GetErrorCode(parser));
}
// We have to temporarily clear an exception before we can release local
@@ -1081,9 +1071,7 @@ static void appendBytes(JNIEnv* env, jobject object, jint pointer,
if (!XML_Parse(parser, ((char*) bytes) + offset, length, XML_FALSE)
&& !env->ExceptionCheck()) {
- jclass clazz = env->FindClass("org/apache/harmony/xml/ExpatException");
- const char* errorMessage = XML_ErrorString(XML_GetErrorCode(parser));
- env->ThrowNew(clazz, errorMessage);
+ jniThrowExpatException(env, XML_GetErrorCode(parser));
}
// We have to temporarily clear an exception before we can release local