Bug Summary

File:bridges/source/jni_uno/jni_bridge.cxx
Location:line 172, column 22
Description:Dereference of null pointer (loaded from variable 'ppJavaI')

Annotated Source Code

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 *
8 * OpenOffice.org - a multi-platform office productivity suite
9 *
10 * This file is part of OpenOffice.org.
11 *
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
15 *
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
21 *
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
26 *
27 ************************************************************************/
28
29
30#include "jni_bridge.h"
31
32#include "jvmaccess/unovirtualmachine.hxx"
33#include "rtl/ref.hxx"
34#include "rtl/unload.h"
35#include "rtl/strbuf.hxx"
36#include "uno/lbnames.h"
37
38
39using namespace ::std;
40using namespace ::rtl;
41using namespace ::osl;
42using namespace ::jni_uno;
43
44namespace
45{
46extern "C"
47{
48
49//------------------------------------------------------------------------------
50void SAL_CALL Mapping_acquire( uno_Mapping * mapping )
51 SAL_THROW_EXTERN_C()throw ()
52{
53 Mapping const * that = static_cast< Mapping const * >( mapping );
54 that->m_bridge->acquire();
55}
56
57//------------------------------------------------------------------------------
58void SAL_CALL Mapping_release( uno_Mapping * mapping )
59 SAL_THROW_EXTERN_C()throw ()
60{
61 Mapping const * that = static_cast< Mapping const * >( mapping );
62 that->m_bridge->release();
63}
64
65//------------------------------------------------------------------------------
66void SAL_CALL Mapping_map_to_uno(
67 uno_Mapping * mapping, void ** ppOut,
68 void * pIn, typelib_InterfaceTypeDescription * td )
69 SAL_THROW_EXTERN_C()throw ()
70{
71 uno_Interface ** ppUnoI = (uno_Interface **)ppOut;
72 jobject javaI = (jobject) pIn;
73
74 OSL_ASSERT( sizeof (void *) == sizeof (jobject) )do { if (true && (!(sizeof (void *) == sizeof (jobject
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "74" ": "), "OSL_ASSERT: %s", "sizeof (void *) == sizeof (jobject)"
); } } while (false)
;
75 OSL_ENSURE( ppUnoI && td, "### null ptr!" )do { if (true && (!(ppUnoI && td))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "75" ": "), "%s", "### null ptr!"); } } while (false)
;
76
77 if (0 == javaI)
78 {
79 if (0 != *ppUnoI)
80 {
81 uno_Interface * p = *(uno_Interface **)ppUnoI;
82 (*p->release)( p );
83 *ppUnoI = 0;
84 }
85 }
86 else
87 {
88 try
89 {
90 Bridge const * bridge =
91 static_cast< Mapping const * >( mapping )->m_bridge;
92 JNI_guarded_context jni(
93 bridge->m_jni_info,
94 reinterpret_cast< ::jvmaccess::UnoVirtualMachine * >(
95 bridge->m_java_env->pContext ) );
96
97 JNI_interface_type_info const * info =
98 static_cast< JNI_interface_type_info const * >(
99 bridge->m_jni_info->get_type_info(
100 jni, (typelib_TypeDescription *)td ) );
101 uno_Interface * pUnoI = bridge->map_to_uno( jni, javaI, info );
102 if (0 != *ppUnoI)
103 {
104 uno_Interface * p = *(uno_Interface **)ppUnoI;
105 (*p->release)( p );
106 }
107 *ppUnoI = pUnoI;
108 }
109 catch (const BridgeRuntimeError & err)
110 {
111#if OSL_DEBUG_LEVEL1 > 0
112 OString cstr_msg(
113 OUStringToOString(
114 OUSTR("[jni_uno bridge error] ")::rtl::OUString( (&("[jni_uno bridge error] ")[0]), ((sal_Int32
)((sizeof ("[jni_uno bridge error] ") / sizeof (("[jni_uno bridge error] "
)[0]))-1)), (((rtl_TextEncoding) 11)) )
+ err.m_message,
115 RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11)) ) );
116 OSL_FAIL( cstr_msg.getStr() )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "116" ": "), "%s", cstr_msg.getStr()); } } while (false)
;
117#else
118 (void) err; // unused
119#endif
120 }
121 catch (const ::jvmaccess::VirtualMachine::AttachGuard::CreationException &)
122 {
123 OSL_FAIL(do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "125" ": "), "%s", "[jni_uno bridge error] attaching current thread "
"to java failed!"); } } while (false)
124 "[jni_uno bridge error] attaching current thread "do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "125" ": "), "%s", "[jni_uno bridge error] attaching current thread "
"to java failed!"); } } while (false)
125 "to java failed!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "125" ": "), "%s", "[jni_uno bridge error] attaching current thread "
"to java failed!"); } } while (false)
;
126 }
127 }
128}
129
130//------------------------------------------------------------------------------
131void SAL_CALL Mapping_map_to_java(
132 uno_Mapping * mapping, void ** ppOut,
133 void * pIn, typelib_InterfaceTypeDescription * td )
134 SAL_THROW_EXTERN_C()throw ()
135{
136 jobject * ppJavaI = (jobject *) ppOut;
137 uno_Interface * pUnoI = (uno_Interface *)pIn;
138
139 OSL_ASSERT( sizeof (void *) == sizeof (jobject) )do { if (true && (!(sizeof (void *) == sizeof (jobject
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "139" ": "), "OSL_ASSERT: %s", "sizeof (void *) == sizeof (jobject)"
); } } while (false)
;
140 OSL_ENSURE( ppJavaI && td, "### null ptr!" )do { if (true && (!(ppJavaI && td))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "140" ": "), "%s", "### null ptr!"); } } while (false)
;
141
142 try
143 {
144 if (0 == pUnoI)
1
Taking false branch
145 {
146 if (0 != *ppJavaI)
147 {
148 Bridge const * bridge =
149 static_cast< Mapping const * >( mapping )->m_bridge;
150 JNI_guarded_context jni(
151 bridge->m_jni_info,
152 reinterpret_cast< ::jvmaccess::UnoVirtualMachine * >(
153 bridge->m_java_env->pContext ) );
154 jni->DeleteGlobalRef( *ppJavaI );
155 *ppJavaI = 0;
156 }
157 }
158 else
159 {
160 Bridge const * bridge =
161 static_cast< Mapping const * >( mapping )->m_bridge;
162 JNI_guarded_context jni(
163 bridge->m_jni_info,
164 reinterpret_cast< ::jvmaccess::UnoVirtualMachine * >(
165 bridge->m_java_env->pContext ) );
166
167 JNI_interface_type_info const * info =
168 static_cast< JNI_interface_type_info const * >(
169 bridge->m_jni_info->get_type_info(
170 jni, (typelib_TypeDescription *)td ) );
171 jobject jlocal = bridge->map_to_java( jni, pUnoI, info );
172 if (0 != *ppJavaI)
2
Dereference of null pointer (loaded from variable 'ppJavaI')
173 jni->DeleteGlobalRef( *ppJavaI );
174 *ppJavaI = jni->NewGlobalRef( jlocal );
175 jni->DeleteLocalRef( jlocal );
176 }
177 }
178 catch (const BridgeRuntimeError & err)
179 {
180#if OSL_DEBUG_LEVEL1 > 0
181 OString cstr_msg(
182 OUStringToOString(
183 OUSTR("[jni_uno bridge error] ")::rtl::OUString( (&("[jni_uno bridge error] ")[0]), ((sal_Int32
)((sizeof ("[jni_uno bridge error] ") / sizeof (("[jni_uno bridge error] "
)[0]))-1)), (((rtl_TextEncoding) 11)) )
+ err.m_message,
184 RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11)) ) );
185 OSL_FAIL( cstr_msg.getStr() )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "185" ": "), "%s", cstr_msg.getStr()); } } while (false)
;
186#else
187 (void) err; // unused
188#endif
189 }
190 catch (const ::jvmaccess::VirtualMachine::AttachGuard::CreationException &)
191 {
192 OSL_FAIL(do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "193" ": "), "%s", "[jni_uno bridge error] attaching current thread to java failed!"
); } } while (false)
193 "[jni_uno bridge error] attaching current thread to java failed!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "193" ": "), "%s", "[jni_uno bridge error] attaching current thread to java failed!"
); } } while (false)
;
194 }
195}
196
197//______________________________________________________________________________
198void SAL_CALL Bridge_free( uno_Mapping * mapping )
199 SAL_THROW_EXTERN_C()throw ()
200{
201 Mapping * that = static_cast< Mapping * >( mapping );
202 delete that->m_bridge;
203}
204
205}
206
207rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT{ {rtl_moduleCount_acquire,rtl_moduleCount_release}, rtl_moduleCount_canUnload
, 0, {0, 0}}
;
208
209}
210
211namespace jni_uno
212{
213
214//______________________________________________________________________________
215void Bridge::acquire() const SAL_THROW(())
216{
217 if (1 == osl_incrementInterlockedCount( &m_ref ))
218 {
219 if (m_registered_java2uno)
220 {
221 uno_Mapping * mapping = const_cast< Mapping * >( &m_java2uno );
222 uno_registerMapping(
223 &mapping, Bridge_free,
224 m_java_env, (uno_Environment *)m_uno_env, 0 );
225 }
226 else
227 {
228 uno_Mapping * mapping = const_cast< Mapping * >( &m_uno2java );
229 uno_registerMapping(
230 &mapping, Bridge_free,
231 (uno_Environment *)m_uno_env, m_java_env, 0 );
232 }
233 }
234}
235
236//______________________________________________________________________________
237void Bridge::release() const SAL_THROW(())
238{
239 if (! osl_decrementInterlockedCount( &m_ref ))
240 {
241 uno_revokeMapping(
242 m_registered_java2uno
243 ? const_cast< Mapping * >( &m_java2uno )
244 : const_cast< Mapping * >( &m_uno2java ) );
245 }
246}
247
248//______________________________________________________________________________
249Bridge::Bridge(
250 uno_Environment * java_env, uno_ExtEnvironment * uno_env,
251 bool registered_java2uno )
252 : m_ref( 1 ),
253 m_uno_env( uno_env ),
254 m_java_env( java_env ),
255 m_registered_java2uno( registered_java2uno )
256{
257 // bootstrapping bridge jni_info
258 m_jni_info = JNI_info::get_jni_info(
259 reinterpret_cast< ::jvmaccess::UnoVirtualMachine * >(
260 m_java_env->pContext ) );
261
262 OSL_ASSERT( 0 != m_java_env && 0 != m_uno_env )do { if (true && (!(0 != m_java_env && 0 != m_uno_env
))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "262" ": "), "OSL_ASSERT: %s", "0 != m_java_env && 0 != m_uno_env"
); } } while (false)
;
263 (*((uno_Environment *)m_uno_env)->acquire)( (uno_Environment *)m_uno_env );
264 (*m_java_env->acquire)( m_java_env );
265
266 // java2uno
267 m_java2uno.acquire = Mapping_acquire;
268 m_java2uno.release = Mapping_release;
269 m_java2uno.mapInterface = Mapping_map_to_uno;
270 m_java2uno.m_bridge = this;
271 // uno2java
272 m_uno2java.acquire = Mapping_acquire;
273 m_uno2java.release = Mapping_release;
274 m_uno2java.mapInterface = Mapping_map_to_java;
275 m_uno2java.m_bridge = this;
276
277 (*g_moduleCount.modCnt.acquire)( &g_moduleCount.modCnt );
278}
279
280//______________________________________________________________________________
281Bridge::~Bridge() SAL_THROW(())
282{
283 (*m_java_env->release)( m_java_env );
284 (*((uno_Environment *)m_uno_env)->release)( (uno_Environment *)m_uno_env );
285
286 (*g_moduleCount.modCnt.release)( &g_moduleCount.modCnt );
287}
288
289
290//______________________________________________________________________________
291void JNI_context::java_exc_occurred() const
292{
293 // !don't rely on JNI_info!
294
295 JLocalAutoRef jo_exc( *this, m_env->ExceptionOccurred() );
296 m_env->ExceptionClear();
297 OSL_ASSERT( jo_exc.is() )do { if (true && (!(jo_exc.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "297" ": "), "OSL_ASSERT: %s", "jo_exc.is()"); } } while
(false)
;
298 if (! jo_exc.is())
299 {
300 throw BridgeRuntimeError(
301 OUSTR("java exception occurred, but not available!?")::rtl::OUString( (&("java exception occurred, but not available!?"
)[0]), ((sal_Int32)((sizeof ("java exception occurred, but not available!?"
) / sizeof (("java exception occurred, but not available!?")[
0]))-1)), (((rtl_TextEncoding) 11)) )
+
302 get_stack_trace() );
303 }
304
305 // call toString(); don't rely on m_jni_info
306 jclass jo_class = m_env->FindClass( "java/lang/Object" );
307 if (JNI_FALSE0 != m_env->ExceptionCheck())
308 {
309 m_env->ExceptionClear();
310 throw BridgeRuntimeError(
311 OUSTR("cannot get class java.lang.Object!")::rtl::OUString( (&("cannot get class java.lang.Object!")
[0]), ((sal_Int32)((sizeof ("cannot get class java.lang.Object!"
) / sizeof (("cannot get class java.lang.Object!")[0]))-1)), (
((rtl_TextEncoding) 11)) )
+ get_stack_trace() );
312 }
313 JLocalAutoRef jo_Object( *this, jo_class );
314 // method Object.toString()
315 jmethodID method_Object_toString = m_env->GetMethodID(
316 (jclass) jo_Object.get(), "toString", "()Ljava/lang/String;" );
317 if (JNI_FALSE0 != m_env->ExceptionCheck())
318 {
319 m_env->ExceptionClear();
320 throw BridgeRuntimeError(
321 OUSTR("cannot get method id of java.lang.Object.toString()!")::rtl::OUString( (&("cannot get method id of java.lang.Object.toString()!"
)[0]), ((sal_Int32)((sizeof ("cannot get method id of java.lang.Object.toString()!"
) / sizeof (("cannot get method id of java.lang.Object.toString()!"
)[0]))-1)), (((rtl_TextEncoding) 11)) )
+
322 get_stack_trace() );
323 }
324 OSL_ASSERT( 0 != method_Object_toString )do { if (true && (!(0 != method_Object_toString))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "324" ": "), "OSL_ASSERT: %s", "0 != method_Object_toString"
); } } while (false)
;
325
326 JLocalAutoRef jo_descr(
327 *this, m_env->CallObjectMethodA(
328 jo_exc.get(), method_Object_toString, 0 ) );
329 if (m_env->ExceptionCheck()) // no chance at all
330 {
331 m_env->ExceptionClear();
332 throw BridgeRuntimeError(
333 OUSTR("error examining java exception object!")::rtl::OUString( (&("error examining java exception object!"
)[0]), ((sal_Int32)((sizeof ("error examining java exception object!"
) / sizeof (("error examining java exception object!")[0]))-1
)), (((rtl_TextEncoding) 11)) )
+
334 get_stack_trace() );
335 }
336
337 jsize len = m_env->GetStringLength( (jstring) jo_descr.get() );
338 SAL_WNODEPRECATED_DECLARATIONS_PUSH
339 auto_ptr< rtl_mem > ustr_mem(
340 rtl_mem::allocate(
341 sizeof (rtl_uString) + (len * sizeof (sal_Unicode)) ) );
342 SAL_WNODEPRECATED_DECLARATIONS_POP
343 rtl_uString * ustr = (rtl_uString *)ustr_mem.get();
344 m_env->GetStringRegion( (jstring) jo_descr.get(), 0, len, ustr->buffer );
345 if (m_env->ExceptionCheck())
346 {
347 m_env->ExceptionClear();
348 throw BridgeRuntimeError(
349 OUSTR("invalid java string object!")::rtl::OUString( (&("invalid java string object!")[0]), (
(sal_Int32)((sizeof ("invalid java string object!") / sizeof (
("invalid java string object!")[0]))-1)), (((rtl_TextEncoding
) 11)) )
+ get_stack_trace() );
350 }
351 ustr->refCount = 1;
352 ustr->length = len;
353 ustr->buffer[ len ] = '\0';
354 OUString message( (rtl_uString *)ustr_mem.release(), SAL_NO_ACQUIRE );
355
356 throw BridgeRuntimeError( message + get_stack_trace( jo_exc.get() ) );
357}
358
359//______________________________________________________________________________
360void JNI_context::getClassForName(
361 jclass * classClass, jmethodID * methodForName) const
362{
363 jclass c = m_env->FindClass("java/lang/Class");
364 if (c != 0) {
365 *methodForName = m_env->GetStaticMethodID(
366 c, "forName",
367 "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;");
368 }
369 *classClass = c;
370}
371
372//______________________________________________________________________________
373jclass JNI_context::findClass(
374 char const * name, jclass classClass, jmethodID methodForName,
375 bool inException) const
376{
377 jclass c = 0;
378 JLocalAutoRef s(*this, m_env->NewStringUTF(name));
379 if (s.is()) {
380 jvalue a[3];
381 a[0].l = s.get();
382 a[1].z = JNI_FALSE0;
383 a[2].l = m_class_loader;
384 c = static_cast< jclass >(
385 m_env->CallStaticObjectMethodA(classClass, methodForName, a));
386 }
387 if (!inException) {
388 ensure_no_exception();
389 }
390 return c;
391}
392
393//______________________________________________________________________________
394OUString JNI_context::get_stack_trace( jobject jo_exc ) const
395{
396 JLocalAutoRef jo_JNI_proxy(
397 *this,
398 find_class( *this, "com.sun.star.bridges.jni_uno.JNI_proxy", true ) );
399 if (assert_no_exception())
400 {
401 // static method JNI_proxy.get_stack_trace()
402 jmethodID method = m_env->GetStaticMethodID(
403 (jclass) jo_JNI_proxy.get(), "get_stack_trace",
404 "(Ljava/lang/Throwable;)Ljava/lang/String;" );
405 if (assert_no_exception() && (0 != method))
406 {
407 jvalue arg;
408 arg.l = jo_exc;
409 JLocalAutoRef jo_stack_trace(
410 *this, m_env->CallStaticObjectMethodA(
411 (jclass) jo_JNI_proxy.get(), method, &arg ) );
412 if (assert_no_exception())
413 {
414 jsize len =
415 m_env->GetStringLength( (jstring) jo_stack_trace.get() );
416 SAL_WNODEPRECATED_DECLARATIONS_PUSH
417 auto_ptr< rtl_mem > ustr_mem(
418 rtl_mem::allocate(
419 sizeof (rtl_uString) + (len * sizeof (sal_Unicode)) ) );
420 SAL_WNODEPRECATED_DECLARATIONS_POP
421 rtl_uString * ustr = (rtl_uString *)ustr_mem.get();
422 m_env->GetStringRegion(
423 (jstring) jo_stack_trace.get(), 0, len, ustr->buffer );
424 if (assert_no_exception())
425 {
426 ustr->refCount = 1;
427 ustr->length = len;
428 ustr->buffer[ len ] = '\0';
429 return OUString(
430 (rtl_uString *)ustr_mem.release(), SAL_NO_ACQUIRE );
431 }
432 }
433 }
434 }
435 return OUString();
436}
437
438}
439
440using namespace ::jni_uno;
441
442extern "C"
443{
444namespace
445{
446
447//------------------------------------------------------------------------------
448void SAL_CALL java_env_disposing( uno_Environment * java_env )
449 SAL_THROW_EXTERN_C()throw ()
450{
451 ::jvmaccess::UnoVirtualMachine * machine =
452 reinterpret_cast< ::jvmaccess::UnoVirtualMachine * >(
453 java_env->pContext );
454 java_env->pContext = 0;
455 machine->release();
456}
457}
458
459//------------------------------------------------------------------------------
460void SAL_CALL uno_initEnvironment( uno_Environment * java_env )
461 SAL_THROW_EXTERN_C()throw ()
462{
463 java_env->environmentDisposing = java_env_disposing;
464 java_env->pExtEnv = 0; // no extended support
465 OSL_ASSERT( 0 != java_env->pContext )do { if (true && (!(0 != java_env->pContext))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "465" ": "), "OSL_ASSERT: %s", "0 != java_env->pContext"
); } } while (false)
;
466
467 ::jvmaccess::UnoVirtualMachine * machine =
468 reinterpret_cast< ::jvmaccess::UnoVirtualMachine * >(
469 java_env->pContext );
470 machine->acquire();
471}
472
473//------------------------------------------------------------------------------
474void SAL_CALL uno_ext_getMapping(
475 uno_Mapping ** ppMapping, uno_Environment * pFrom, uno_Environment * pTo )
476 SAL_THROW_EXTERN_C()throw ()
477{
478 OSL_ASSERT( 0 != ppMapping && 0 != pFrom && 0 != pTo )do { if (true && (!(0 != ppMapping && 0 != pFrom
&& 0 != pTo))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "478" ": "), "OSL_ASSERT: %s", "0 != ppMapping && 0 != pFrom && 0 != pTo"
); } } while (false)
;
479 if (0 != *ppMapping)
480 {
481 (*(*ppMapping)->release)( *ppMapping );
482 *ppMapping = 0;
483 }
484
485 OSL_ASSERT( JNI_FALSE == sal_False )do { if (true && (!(0 == ((sal_Bool)0)))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "485" ": "), "OSL_ASSERT: %s", "JNI_FALSE == sal_False")
; } } while (false)
;
486 OSL_ASSERT( JNI_TRUE == sal_True )do { if (true && (!(1 == ((sal_Bool)1)))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "486" ": "), "OSL_ASSERT: %s", "JNI_TRUE == sal_True"); }
} while (false)
;
487 OSL_ASSERT( sizeof (jboolean) == sizeof (sal_Bool) )do { if (true && (!(sizeof (jboolean) == sizeof (sal_Bool
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "487" ": "), "OSL_ASSERT: %s", "sizeof (jboolean) == sizeof (sal_Bool)"
); } } while (false)
;
488 OSL_ASSERT( sizeof (jchar) == sizeof (sal_Unicode) )do { if (true && (!(sizeof (jchar) == sizeof (sal_Unicode
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "488" ": "), "OSL_ASSERT: %s", "sizeof (jchar) == sizeof (sal_Unicode)"
); } } while (false)
;
489 OSL_ASSERT( sizeof (jdouble) == sizeof (double) )do { if (true && (!(sizeof (jdouble) == sizeof (double
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "489" ": "), "OSL_ASSERT: %s", "sizeof (jdouble) == sizeof (double)"
); } } while (false)
;
490 OSL_ASSERT( sizeof (jfloat) == sizeof (float) )do { if (true && (!(sizeof (jfloat) == sizeof (float)
))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "490" ": "), "OSL_ASSERT: %s", "sizeof (jfloat) == sizeof (float)"
); } } while (false)
;
491 OSL_ASSERT( sizeof (jbyte) == sizeof (sal_Int8) )do { if (true && (!(sizeof (jbyte) == sizeof (sal_Int8
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "491" ": "), "OSL_ASSERT: %s", "sizeof (jbyte) == sizeof (sal_Int8)"
); } } while (false)
;
492 OSL_ASSERT( sizeof (jshort) == sizeof (sal_Int16) )do { if (true && (!(sizeof (jshort) == sizeof (sal_Int16
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "492" ": "), "OSL_ASSERT: %s", "sizeof (jshort) == sizeof (sal_Int16)"
); } } while (false)
;
493 OSL_ASSERT( sizeof (jint) == sizeof (sal_Int32) )do { if (true && (!(sizeof (jint) == sizeof (sal_Int32
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "493" ": "), "OSL_ASSERT: %s", "sizeof (jint) == sizeof (sal_Int32)"
); } } while (false)
;
494 OSL_ASSERT( sizeof (jlong) == sizeof (sal_Int64) )do { if (true && (!(sizeof (jlong) == sizeof (sal_Int64
)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "494" ": "), "OSL_ASSERT: %s", "sizeof (jlong) == sizeof (sal_Int64)"
); } } while (false)
;
495 if ((JNI_FALSE0 == sal_False((sal_Bool)0)) &&
496 (JNI_TRUE1 == sal_True((sal_Bool)1)) &&
497 (sizeof (jboolean) == sizeof (sal_Bool)) &&
498 (sizeof (jchar) == sizeof (sal_Unicode)) &&
499 (sizeof (jdouble) == sizeof (double)) &&
500 (sizeof (jfloat) == sizeof (float)) &&
501 (sizeof (jbyte) == sizeof (sal_Int8)) &&
502 (sizeof (jshort) == sizeof (sal_Int16)) &&
503 (sizeof (jint) == sizeof (sal_Int32)) &&
504 (sizeof (jlong) == sizeof (sal_Int64)))
505 {
506 OUString const & from_env_typename =
507 OUString::unacquired( &pFrom->pTypeName );
508 OUString const & to_env_typename =
509 OUString::unacquired( &pTo->pTypeName );
510
511 uno_Mapping * mapping = 0;
512
513 try
514 {
515 if ( from_env_typename == UNO_LB_JAVA"java" && to_env_typename == UNO_LB_UNO"uno" )
516 {
517 Bridge * bridge =
518 new Bridge( pFrom, pTo->pExtEnv, true ); // ref count = 1
519 mapping = &bridge->m_java2uno;
520 uno_registerMapping(
521 &mapping, Bridge_free,
522 pFrom, (uno_Environment *)pTo->pExtEnv, 0 );
523 }
524 else if ( from_env_typename == UNO_LB_UNO"uno" && to_env_typename == UNO_LB_JAVA"java" )
525 {
526 Bridge * bridge =
527 new Bridge( pTo, pFrom->pExtEnv, false ); // ref count = 1
528 mapping = &bridge->m_uno2java;
529 uno_registerMapping(
530 &mapping, Bridge_free,
531 (uno_Environment *)pFrom->pExtEnv, pTo, 0 );
532 }
533 }
534 catch (const BridgeRuntimeError & err)
535 {
536#if OSL_DEBUG_LEVEL1 > 0
537 OString cstr_msg(
538 OUStringToOString(
539 OUSTR("[jni_uno bridge error] ")::rtl::OUString( (&("[jni_uno bridge error] ")[0]), ((sal_Int32
)((sizeof ("[jni_uno bridge error] ") / sizeof (("[jni_uno bridge error] "
)[0]))-1)), (((rtl_TextEncoding) 11)) )
+ err.m_message,
540 RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11)) ) );
541 OSL_FAIL( cstr_msg.getStr() )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "541" ": "), "%s", cstr_msg.getStr()); } } while (false)
;
542#else
543 (void) err; // unused
544#endif
545 }
546 catch (const ::jvmaccess::VirtualMachine::AttachGuard::CreationException &)
547 {
548 OSL_FAIL(do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "550" ": "), "%s", "[jni_uno bridge error] attaching current thread "
"to java failed!"); } } while (false)
549 "[jni_uno bridge error] attaching current thread "do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "550" ": "), "%s", "[jni_uno bridge error] attaching current thread "
"to java failed!"); } } while (false)
550 "to java failed!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_bridge.cxx"
":" "550" ": "), "%s", "[jni_uno bridge error] attaching current thread "
"to java failed!"); } } while (false)
;
551 }
552
553 *ppMapping = mapping;
554 }
555}
556
557//------------------------------------------------------------------------------
558SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) sal_Bool SAL_CALL component_canUnload( TimeValue * pTime )
559 SAL_THROW_EXTERN_C()throw ()
560{
561 return (*g_moduleCount.canUnload)( &g_moduleCount, pTime );
562}
563}
564
565/* vim:set shiftwidth=4 softtabstop=4 expandtab: */