diff options
author | Rajith Muditha Attapattu <rajith@apache.org> | 2012-06-07 17:35:07 +0000 |
---|---|---|
committer | Rajith Muditha Attapattu <rajith@apache.org> | 2012-06-07 17:35:07 +0000 |
commit | 3fa6a5e39c2ff12e9b37426b5e7f0e7f88a345b9 (patch) | |
tree | 70b904faec7a85c64956e9af4771e3acb4b8e51b | |
parent | abcc7316bedddc6f5f5930e3661a3e6d06ce30cf (diff) | |
download | qpid-python-3fa6a5e39c2ff12e9b37426b5e7f0e7f88a345b9.tar.gz |
QPID-4027 Adeed error handling when converting from Variant to Java
types.
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/address-refactor2@1347730 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/bindings/swig_java_cpp_helper.i | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/qpid/cpp/bindings/swig_java_cpp_helper.i b/qpid/cpp/bindings/swig_java_cpp_helper.i index 017b0e0e93..e782d20535 100644 --- a/qpid/cpp/bindings/swig_java_cpp_helper.i +++ b/qpid/cpp/bindings/swig_java_cpp_helper.i @@ -78,7 +78,8 @@ static jmethodID JAVA_DOUBLE_VALUE_METHOD; static jclass JAVA_ILLEGAL_ARGUMENT_EXP; static jclass JAVA_JNI_LAYER_EXP; -static jmethodID JAVA_JNI_LAYER_EXP_CTOR; // takes a msg and a throwable. +static jmethodID JAVA_JNI_LAYER_EXP_CTOR1; // takes a msg. +static jmethodID JAVA_JNI_LAYER_EXP_CTOR2; // takes a msg and a throwable. static jobject createGlobalRef(JNIEnv* env,jobject obj) { @@ -158,7 +159,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) JAVA_ILLEGAL_ARGUMENT_EXP = static_cast<jclass>(createGlobalRef(env,findClass(env,"java/lang/IllegalArgumentException"))); JAVA_JNI_LAYER_EXP = static_cast<jclass>(createGlobalRef(env,findClass(env,"org/apache/qpid/messaging/cpp/JNILayerException"))); - JAVA_JNI_LAYER_EXP_CTOR = getMethodID(env,JAVA_JNI_LAYER_EXP, "<init>", "(Ljava/lang/String;Ljava/lang/Throwable;)V"); + JAVA_JNI_LAYER_EXP_CTOR1 = getMethodID(env,JAVA_JNI_LAYER_EXP, "<init>", "(Ljava/lang/String;)V"); + JAVA_JNI_LAYER_EXP_CTOR2 = getMethodID(env,JAVA_JNI_LAYER_EXP, "<init>", "(Ljava/lang/String;Ljava/lang/Throwable;)V"); if (env->ExceptionCheck()) { @@ -172,18 +174,27 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) return JNI_VERSION_1_4; } -static bool checkAndThrowException(JNIEnv* env, const char* msg) +static bool checkAndThrowJNILaylerException(JNIEnv* env, const char* msg) { jthrowable cause = env->ExceptionOccurred(); if (cause) { - jthrowable ex = static_cast<jthrowable>(env->NewObject(JAVA_JNI_LAYER_EXP, JAVA_JNI_LAYER_EXP_CTOR, msg, cause)); + jthrowable ex = static_cast<jthrowable>(env->NewObject(JAVA_JNI_LAYER_EXP, JAVA_JNI_LAYER_EXP_CTOR2, msg, cause)); env->Throw(ex); + env->DeleteLocalRef(cause); + env->DeleteLocalRef(ex); return true; } return false; } +static void throwJNILayerException(JNIEnv* env, const char* msg) +{ + jthrowable ex = static_cast<jthrowable>(env->NewObject(JAVA_JNI_LAYER_EXP, JAVA_JNI_LAYER_EXP_CTOR1, msg)); + env->Throw(ex); + env->DeleteLocalRef(ex); +} + static jobject newJavaBoolean(JNIEnv* env, jboolean arg) { return env->NewObject(JAVA_BOOLEAN_CLASS, JAVA_BOOLEAN_CTOR,arg); @@ -300,7 +311,7 @@ static qpid::types::Variant convertJavaObjectToVariant(JNIEnv* env, jobject obj) return 0; } - if (checkAndThrowException(env,"Exception occured when converting Java object to Variant")) + if (checkAndThrowJNILaylerException(env,"Exception occured when converting Java object to Variant")) { return 0; } @@ -377,8 +388,6 @@ ReadOnlyVariantMapWrapper::~ReadOnlyVariantMapWrapper() } } -// **** handle unsupported types -// Add a generic error checking mechanism to see if the java methods have a thrown an error. jobject ReadOnlyVariantMapWrapper::get(const std::string key) const { using namespace qpid::types; @@ -443,6 +452,16 @@ jobject ReadOnlyVariantMapWrapper::get(const std::string key) const result = newJavaString(env_,v.asString()); break; } + + case VAR_MAP : { + throwJNILayerException(env_,"The key maps to a Varient::Map. Unsupported type for message properties"); + break; + } + + case VAR_LIST : { + throwJNILayerException(env_,"The key maps to a Varient::List. Unsupported type for message properties"); + break; + } } return result; |