diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2014-12-11 13:08:29 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-12-11 13:09:02 +0100 |
commit | ebd2d28c64146dd3c0686556f7ec344c8b92c624 (patch) | |
tree | fca17964b235eb7af19c6542ac9635686964ce65 /bridges/source/jni_uno | |
parent | f2c6bbf4606d3e5274e5ba621e3a8b7f939d2f82 (diff) |
Fix JNI calls to AsynchronousFinalizer
...make sure the class is actually found, etc.
Change-Id: I5459d531be39b07594a975ae708a7611d1667a2f
Diffstat (limited to 'bridges/source/jni_uno')
-rw-r--r-- | bridges/source/jni_uno/jni_bridge.cxx | 75 | ||||
-rw-r--r-- | bridges/source/jni_uno/jni_info.cxx | 16 | ||||
-rw-r--r-- | bridges/source/jni_uno/jni_info.h | 4 |
3 files changed, 39 insertions, 56 deletions
diff --git a/bridges/source/jni_uno/jni_bridge.cxx b/bridges/source/jni_uno/jni_bridge.cxx index 192aaf1b690b..7be6363123f7 100644 --- a/bridges/source/jni_uno/jni_bridge.cxx +++ b/bridges/source/jni_uno/jni_bridge.cxx @@ -434,29 +434,16 @@ void SAL_CALL java_env_dispose(uno_Environment * env) { } if (async != nullptr) { try { - jvmaccess::VirtualMachine::AttachGuard g( - envData->machine->getVirtualMachine()); - JNIEnv * jniEnv = g.getEnvironment(); - jclass cl = jniEnv->FindClass( - "com/sun/star/lib/util/AsynchronousFinalizer"); - if (cl == nullptr) { - jniEnv->ExceptionClear(); - SAL_WARN("bridges", "exception in FindClass"); - } else { - jmethodID id = jniEnv->GetMethodID(cl, "drain", "()V"); - if (id == nullptr) { - jniEnv->ExceptionClear(); - SAL_WARN("bridges", "exception in GetMethodID"); - } else { - jniEnv->CallObjectMethod(async, id); - if (jniEnv->ExceptionOccurred()) { - jniEnv->ExceptionClear(); - SAL_WARN( - "bridges", "exception in CallObjectMethod"); - } - } - } - jniEnv->DeleteGlobalRef(async); + JNI_guarded_context jni(envData->info, envData->machine); + jni->CallObjectMethodA( + async, envData->info->m_method_AsynchronousFinalizer_drain, + nullptr); + jni.ensure_no_exception(); + jni->DeleteGlobalRef(async); + } catch (const BridgeRuntimeError & e) { + SAL_WARN( + "bridges", + "ignoring BridgeRuntimeError \"" << e.m_message << "\""); } catch ( jvmaccess::VirtualMachine::AttachGuard::CreationException &) { @@ -499,39 +486,15 @@ SAL_DLLPUBLIC_EXPORT void SAL_CALL uno_initEnvironment( uno_Environment * java_e std::unique_ptr<jni_uno::JniUnoEnvironmentData> envData( new jni_uno::JniUnoEnvironmentData(vm)); { - jvmaccess::VirtualMachine::AttachGuard g( - envData->machine->getVirtualMachine()); - JNIEnv * jniEnv = g.getEnvironment(); - jclass cl = jniEnv->FindClass( - "com/sun/star/lib/util/AsynchronousFinalizer"); - if (cl == nullptr) { - jniEnv->ExceptionClear(); - SAL_WARN("bridges", "exception in FindClass"); - //TODO: report failure - } else { - jmethodID id = jniEnv->GetMethodID(cl, "<init>", "()V"); - if (id == nullptr) { - jniEnv->ExceptionClear(); - SAL_WARN("bridges", "exception in GetMethodID"); - //TODO: report failure - } else { - jobject o = jniEnv->NewObject(cl, id); - if (o == nullptr) { - jniEnv->ExceptionClear(); - SAL_WARN("bridges", "exception in NewObject"); - //TODO: report failure - } else { - o = jniEnv->NewGlobalRef(o); - if (o == nullptr) { - jniEnv->ExceptionClear(); - SAL_WARN("bridges", "exception in NewGlobalRef"); - //TODO: report failure - } else { - envData->asynchronousFinalizer = o; - } - } - } - } + JNI_guarded_context jni(envData->info, envData->machine); + JLocalAutoRef ref( + jni, + jni->NewObject( + envData->info->m_class_AsynchronousFinalizer, + envData->info->m_ctor_AsynchronousFinalizer)); + jni.ensure_no_exception(); + envData->asynchronousFinalizer = jni->NewGlobalRef(ref.get()); + jni.ensure_no_exception(); } java_env->pContext = envData.release(); } catch (const BridgeRuntimeError & e) { diff --git a/bridges/source/jni_uno/jni_info.cxx b/bridges/source/jni_uno/jni_info.cxx index aa910f12d5b2..84ac6aaadd3f 100644 --- a/bridges/source/jni_uno/jni_info.cxx +++ b/bridges/source/jni_uno/jni_info.cxx @@ -537,6 +537,8 @@ JNI_info::JNI_info( jni, find_class( jni, "com.sun.star.uno.IEnvironment" ) ); JLocalAutoRef jo_JNI_proxy( jni, find_class( jni, "com.sun.star.bridges.jni_uno.JNI_proxy" ) ); + JLocalAutoRef jo_AsynchronousFinalizer( + jni, find_class( jni, "com.sun.star.lib.util.AsynchronousFinalizer" ) ); // method Object.toString() m_method_Object_toString = jni->GetMethodID( @@ -749,6 +751,17 @@ JNI_info::JNI_info( jni.ensure_no_exception(); assert( 0 != m_field_JNI_proxy_m_oid ); + // ctor AsynchronousFinalizer + m_ctor_AsynchronousFinalizer = jni->GetMethodID( + (jclass) jo_AsynchronousFinalizer.get(), "<init>", "()V" ); + jni.ensure_no_exception(); + assert( 0 != m_ctor_AsynchronousFinalizer ); + // method AsynchronousFinalizer.drain() + m_method_AsynchronousFinalizer_drain = jni->GetMethodID( + (jclass) jo_AsynchronousFinalizer.get(), "drain", "()V" ); + jni.ensure_no_exception(); + assert( 0 != m_method_AsynchronousFinalizer_drain ); + // get java env OUString java_env_type_name( UNO_LB_JAVA ); JLocalAutoRef jo_java( @@ -812,6 +825,8 @@ JNI_info::JNI_info( (jclass) jni->NewGlobalRef( jo_TypeClass.get() ); m_class_JNI_proxy = (jclass) jni->NewGlobalRef( jo_JNI_proxy.get() ); + m_class_AsynchronousFinalizer = + (jclass) jni->NewGlobalRef( jo_AsynchronousFinalizer.get() ); m_class_Character = (jclass) jni->NewGlobalRef( jo_Character.get() ); @@ -896,6 +911,7 @@ void JNI_info::destruct( JNIEnv * jni_env ) jni_env->DeleteGlobalRef( m_class_Boolean ); jni_env->DeleteGlobalRef( m_class_Character ); + jni_env->DeleteGlobalRef( m_class_AsynchronousFinalizer ); jni_env->DeleteGlobalRef( m_class_JNI_proxy ); jni_env->DeleteGlobalRef( m_class_RuntimeException ); jni_env->DeleteGlobalRef( m_class_UnoRuntime ); diff --git a/bridges/source/jni_uno/jni_info.h b/bridges/source/jni_uno/jni_info.h index e030602ff983..e38c4b3db0b0 100644 --- a/bridges/source/jni_uno/jni_info.h +++ b/bridges/source/jni_uno/jni_info.h @@ -150,6 +150,7 @@ public: jclass m_class_Type; jclass m_class_TypeClass; jclass m_class_JNI_proxy; + jclass m_class_AsynchronousFinalizer; jmethodID m_method_Object_toString; jmethodID m_method_Class_getName; @@ -191,6 +192,9 @@ public: jfieldID m_field_JNI_proxy_m_type; jfieldID m_field_JNI_proxy_m_oid; + jmethodID m_ctor_AsynchronousFinalizer; + jmethodID m_method_AsynchronousFinalizer_drain; + ::com::sun::star::uno::TypeDescription m_XInterface_queryInterface_td; ::com::sun::star::uno::Type const & m_Exception_type; ::com::sun::star::uno::Type const & m_RuntimeException_type; |