| File: | jvmaccess/source/virtualmachine.cxx |
| Location: | line 48, column 22 |
| Description: | Called C++ object pointer is null |
| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | /* |
| 3 | * This file is part of the LibreOffice project. |
| 4 | * |
| 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 | * |
| 9 | * This file incorporates work covered by the following license notice: |
| 10 | * |
| 11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 | * contributor license agreements. See the NOTICE file distributed |
| 13 | * with this work for additional information regarding copyright |
| 14 | * ownership. The ASF licenses this file to you under the Apache |
| 15 | * License, Version 2.0 (the "License"); you may not use this file |
| 16 | * except in compliance with the License. You may obtain a copy of |
| 17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 | */ |
| 19 | |
| 20 | #include "jvmaccess/virtualmachine.hxx" |
| 21 | |
| 22 | #include "osl/diagnose.h" |
| 23 | |
| 24 | using jvmaccess::VirtualMachine; |
| 25 | |
| 26 | VirtualMachine::AttachGuard::CreationException::CreationException() |
| 27 | {} |
| 28 | |
| 29 | VirtualMachine::AttachGuard::CreationException::CreationException( |
| 30 | CreationException const &) |
| 31 | {} |
| 32 | |
| 33 | VirtualMachine::AttachGuard::CreationException::~CreationException() |
| 34 | {} |
| 35 | |
| 36 | VirtualMachine::AttachGuard::CreationException & |
| 37 | VirtualMachine::AttachGuard::CreationException::operator =( |
| 38 | CreationException const &) |
| 39 | { |
| 40 | return *this; |
| 41 | } |
| 42 | |
| 43 | VirtualMachine::AttachGuard::AttachGuard( |
| 44 | rtl::Reference< VirtualMachine > const & rMachine): |
| 45 | m_xMachine(rMachine) |
| 46 | { |
| 47 | OSL_ENSURE(m_xMachine.is(), "bad parameter")do { if (true && (!(m_xMachine.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/jvmaccess/source/virtualmachine.cxx" ":" "47" ": "), "%s", "bad parameter"); } } while (false); |
| 48 | m_pEnvironment = m_xMachine->attachThread(&m_bDetach); |
Called C++ object pointer is null | |
| 49 | if (m_pEnvironment == 0) |
| 50 | throw CreationException(); |
| 51 | } |
| 52 | |
| 53 | VirtualMachine::AttachGuard::~AttachGuard() |
| 54 | { |
| 55 | if (m_bDetach) |
| 56 | m_xMachine->detachThread(); |
| 57 | } |
| 58 | |
| 59 | VirtualMachine::VirtualMachine(JavaVM * pVm, int nVersion, bool bDestroy, |
| 60 | JNIEnv * pMainThreadEnv): |
| 61 | m_pVm(pVm), m_nVersion(nVersion), m_bDestroy(bDestroy) |
| 62 | { |
| 63 | (void) pMainThreadEnv; // avoid warnings |
| 64 | #ifdef SOLAR_JAVA1 |
| 65 | OSL_ENSURE(pVm != 0 && nVersion >= JNI_VERSION_1_2 && pMainThreadEnv != 0,do { if (true && (!(pVm != 0 && nVersion >= 0x00010002 && pMainThreadEnv != 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/jvmaccess/source/virtualmachine.cxx" ":" "66" ": "), "%s", "bad parameter"); } } while (false) |
| 66 | "bad parameter")do { if (true && (!(pVm != 0 && nVersion >= 0x00010002 && pMainThreadEnv != 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/jvmaccess/source/virtualmachine.cxx" ":" "66" ": "), "%s", "bad parameter"); } } while (false); |
| 67 | #endif |
| 68 | } |
| 69 | |
| 70 | VirtualMachine::~VirtualMachine() |
| 71 | { |
| 72 | if (m_bDestroy) |
| 73 | { |
| 74 | // Do not destroy the VM. Under Java 1.3, the AWT event loop thread is |
| 75 | // not a daemon thread and is never terminated, so that calling |
| 76 | // DestroyJavaVM (waiting for all non-daemon threads to terminate) hangs |
| 77 | // forever. |
| 78 | /* |
| 79 | jint n = m_pVm->DestroyJavaVM(); |
| 80 | OSL_ENSURE(n == JNI_OK, "JNI: DestroyJavaVM failed"); |
| 81 | */ |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | JNIEnv * VirtualMachine::attachThread(bool * pAttached) const |
| 86 | { |
| 87 | #ifndef SOLAR_JAVA1 |
| 88 | (void) pAttached; |
| 89 | return 0; |
| 90 | #else |
| 91 | OSL_ENSURE(pAttached != 0, "bad parameter")do { if (true && (!(pAttached != 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/jvmaccess/source/virtualmachine.cxx" ":" "91" ": "), "%s", "bad parameter"); } } while (false); |
| 92 | JNIEnv * pEnv; |
| 93 | jint n = m_pVm->GetEnv(reinterpret_cast< void ** >(&pEnv), m_nVersion); |
| 94 | if (n != JNI_OK0 && n != JNI_EDETACHED(-2)) { |
| 95 | OSL_FAIL("JNI: GetEnv failed")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/jvmaccess/source/virtualmachine.cxx" ":" "95" ": "), "%s", "JNI: GetEnv failed"); } } while (false ); |
| 96 | } |
| 97 | if (pEnv == 0) |
| 98 | { |
| 99 | if (m_pVm->AttachCurrentThread |
| 100 | ( |
| 101 | #ifndef ANDROID |
| 102 | reinterpret_cast< void ** >(&pEnv), |
| 103 | #else |
| 104 | // The Android <jni.h> has AttachCurrentThread() taking a |
| 105 | // JNIEnv** and not void ** |
| 106 | &pEnv, |
| 107 | #endif |
| 108 | 0) |
| 109 | != JNI_OK0) |
| 110 | return 0; |
| 111 | *pAttached = true; |
| 112 | } |
| 113 | else |
| 114 | *pAttached = false; |
| 115 | return pEnv; |
| 116 | #endif |
| 117 | } |
| 118 | |
| 119 | void VirtualMachine::detachThread() const |
| 120 | { |
| 121 | #ifdef SOLAR_JAVA1 |
| 122 | if (m_pVm->DetachCurrentThread() != JNI_OK0) { |
| 123 | OSL_FAIL("JNI: DetachCurrentThread failed")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/jvmaccess/source/virtualmachine.cxx" ":" "123" ": "), "%s", "JNI: DetachCurrentThread failed"); } } while (false); |
| 124 | } |
| 125 | #endif |
| 126 | } |
| 127 | |
| 128 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |