Any JNI/UNO bridge experts around? Some assumptions about field ids are apparently not valid for Dalvik
Tor Lillqvist
tml at iki.fi
Fri Mar 23 05:44:11 PDT 2012
It seems that the code assumes the field id for the "Context" field in
com.sun.star.uno.Exception is also valid for that field in
com.sun.star.uno.RuntimeException. This apparently holds for "normal"
JVMs, but not Dalvik? I am still digging into what is actually going
on, need to write some minimal test programs, but just wanted to ask
about this already now in case somebody immediately can think of
something like "yeah, I remember back in 2001 when we discussed
whether that is safe" ;)
I added some debugging output to the JNI_compound_type_info
constructor in bridges/sources/jni_uno/jni_info.cxx, where it calls
GetFieldId for the Exception and RuntimeException types to see what
the returned field ids are:
diff --git a/bridges/source/jni_uno/jni_info.cxx
b/bridges/source/jni_uno/jni_info.cxx
index a5ed28a..8e15979 100644
--- a/bridges/source/jni_uno/jni_info.cxx
+++ b/bridges/source/jni_uno/jni_info.cxx
@@ -302,2 +302,3 @@ JNI_compound_type_info::JNI_compound_type_info(
(jclass) jo_class.get(), "Context", "Ljava/lang/Object;" );
+ fprintf(stderr, "%s:%d %s: m_fields=[%p,%p]\n",
__FUNCTION__, __LINE__, OUStringToOString(uno_name,
RTL_TEXTENCODING_ASCII_US).getStr(), m_fields[0], m_fields[1]);
jni.ensure_no_exception();
@@ -311,2 +312,3 @@ JNI_compound_type_info::JNI_compound_type_info(
+ fprintf(stderr, "%s:%d %s: %d fields\n", __FUNCTION__,
__LINE__, OUStringToOString(uno_name,
RTL_TEXTENCODING_ASCII_US).getStr(), (int)nMembers);
for ( sal_Int32 nPos = 0; nPos < nMembers; ++nPos )
@@ -337,2 +339,3 @@ JNI_compound_type_info::JNI_compound_type_info(
jni.ensure_no_exception();
+ fprintf(stderr, " %s: %p\n", member_name.getStr(),
m_fields[nPos]);
OSL_ASSERT( 0 != m_fields[ nPos ] );
and get this output:
JNI_compound_type_info:303 com.sun.star.uno.Exception: m_fields=[0x0,0x44e29a68]
JNI_compound_type_info:303 com.sun.star.uno.RuntimeException:
m_fields=[0x0,0x44e26c68]
Then shortly after that I get a crash:
JNI WARNING: instance fieldID 0x44e29a68 not valid for class
Lcom/sun/star/uno/RuntimeException;
Note that the fieldID here is the one printed as being for the
Exception type, while the warning message says it is used for
RuntimeExcpetion.
(Yeah, despite claiming that is a "warning", Dalvik then throw its
hands up and quits:
http://androidxref.com/source/xref/dalvik/vm/CheckJni.cpp#364 )
Bells ringing, anyone?
Firstlty, I guess I need to quickly check what that debugging output
says with a "normal" JVM, whether the field ids are
--tml
More information about the LibreOffice
mailing list