Any JNI/UNO bridge experts around? Some assumptions about field ids are apparently not valid for Dalvik

Tor Lillqvist tml at
Fri Mar 23 05:44:11 PDT 2012

It seems that the code assumes the field id for the "Context" field in is also valid for that field in 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
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]);
@@ -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(
+                fprintf(stderr, "  %s: %p\n", member_name.getStr(),
                 OSL_ASSERT( 0 != m_fields[ nPos ] );

and get this output:

JNI_compound_type_info:303 m_fields=[0x0,0x44e29a68]

Then shortly after that I get a crash:

JNI WARNING: instance fieldID 0x44e29a68 not valid for class

Note that the fieldID here is the one printed as being for the
Exception type, while the warning message says it is used for

(Yeah, despite claiming that is a "warning", Dalvik then throw its
hands up and quits: )

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


More information about the LibreOffice mailing list