From abcc7316bedddc6f5f5930e3661a3e6d06ce30cf Mon Sep 17 00:00:00 2001 From: Rajith Muditha Attapattu Date: Thu, 7 Jun 2012 17:35:01 +0000 Subject: QPID-4027 Added error handling when converting between java and variant types. git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/address-refactor2@1347729 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/bindings/swig_java_cpp_helper.i | 17 +++++++++++++++++ qpid/cpp/bindings/swig_java_typemaps.i | 12 +++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'qpid/cpp') diff --git a/qpid/cpp/bindings/swig_java_cpp_helper.i b/qpid/cpp/bindings/swig_java_cpp_helper.i index e7b3332637..017b0e0e93 100644 --- a/qpid/cpp/bindings/swig_java_cpp_helper.i +++ b/qpid/cpp/bindings/swig_java_cpp_helper.i @@ -172,6 +172,18 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) return JNI_VERSION_1_4; } +static bool checkAndThrowException(JNIEnv* env, const char* msg) +{ + jthrowable cause = env->ExceptionOccurred(); + if (cause) + { + jthrowable ex = static_cast(env->NewObject(JAVA_JNI_LAYER_EXP, JAVA_JNI_LAYER_EXP_CTOR, msg, cause)); + env->Throw(ex); + return true; + } + return false; +} + static jobject newJavaBoolean(JNIEnv* env, jboolean arg) { return env->NewObject(JAVA_BOOLEAN_CLASS, JAVA_BOOLEAN_CTOR,arg); @@ -285,8 +297,13 @@ static qpid::types::Variant convertJavaObjectToVariant(JNIEnv* env, jobject obj) else { env->ThrowNew(JAVA_ILLEGAL_ARGUMENT_EXP,"Only primitive types and strings are allowed"); + return 0; } + if (checkAndThrowException(env,"Exception occured when converting Java object to Variant")) + { + return 0; + } return result; } %} diff --git a/qpid/cpp/bindings/swig_java_typemaps.i b/qpid/cpp/bindings/swig_java_typemaps.i index 9d0446d31f..6dbefc1a7e 100644 --- a/qpid/cpp/bindings/swig_java_typemaps.i +++ b/qpid/cpp/bindings/swig_java_typemaps.i @@ -105,7 +105,17 @@ /* -- qpid::types::Variant& -- */ %typemap(in) (const qpid::types::Variant&) { - $1 = new qpid::types::Variant(convertJavaObjectToVariant(jenv,$input)); + qpid::types::Variant v = convertJavaObjectToVariant(jenv,$input); + if (v) + { + $1 = new qpid::types::Variant(v); + } + else + { + // There will be an exception on the java side, + // thrown by convertJavaObjectToVariant method. + return; + } } %typemap(javain) (const qpid::types::Variant&) "$javainput" -- cgit v1.2.1