Bug Summary

File:jvmaccess/source/classpath.cxx
Location:line 56, column 21
Description:Called C++ object pointer is null

Annotated Source Code

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 "sal/config.h"
21
22#include "jvmaccess/classpath.hxx"
23
24#include <vector>
25
26#include "com/sun/star/lang/IllegalArgumentException.hpp"
27#include "com/sun/star/uno/Any.hxx"
28#include "com/sun/star/uno/Reference.hxx"
29#include "com/sun/star/uno/RuntimeException.hpp"
30#include "com/sun/star/uno/XComponentContext.hpp"
31#include "com/sun/star/uno/XInterface.hpp"
32#include "com/sun/star/uri/UriReferenceFactory.hpp"
33#include "com/sun/star/uri/XVndSunStarExpandUrlReference.hpp"
34#include "com/sun/star/util/XMacroExpander.hpp"
35#include "osl/diagnose.h"
36#include "rtl/ustring.hxx"
37#include "sal/types.h"
38
39#if defined SOLAR_JAVA1
40#include "jni.h"
41#endif
42
43namespace {
44
45namespace css = ::com::sun::star;
46
47}
48
49void * ::jvmaccess::ClassPath::doTranslateToUrls(
50 css::uno::Reference< css::uno::XComponentContext > const & context,
51 void * environment, ::rtl::OUString const & classPath)
52{
53 OSL_ASSERT(context.is() && environment != 0)do { if (true && (!(context.is() && environment
!= 0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), (
"legacy.osl"), ("/usr/local/src/libreoffice/jvmaccess/source/classpath.cxx"
":" "53" ": "), "OSL_ASSERT: %s", "context.is() && environment != 0"
); } } while (false)
;
54#if defined SOLAR_JAVA1
55 ::JNIEnv * const env = static_cast< ::JNIEnv * >(environment);
1
Variable 'env' initialized to a null pointer value
56 jclass classUrl(env->FindClass("java/net/URL"));
2
Called C++ object pointer is null
57 if (classUrl == 0) {
58 return 0;
59 }
60 jmethodID ctorUrl(
61 env->GetMethodID(classUrl, "<init>", "(Ljava/lang/String;)V"));
62 if (ctorUrl == 0) {
63 return 0;
64 }
65 ::std::vector< jobject > urls;
66 for (::sal_Int32 i = 0; i != -1;) {
67 ::rtl::OUString url(classPath.getToken(0, ' ', i));
68 if (!url.isEmpty()) {
69 css::uno::Reference< css::uri::XVndSunStarExpandUrlReference >
70 expUrl(
71 css::uri::UriReferenceFactory::create(context)->parse(url),
72 css::uno::UNO_QUERY);
73 if (expUrl.is()) {
74 css::uno::Reference< css::util::XMacroExpander > expander(
75 context->getValueByName(
76 ::rtl::OUString(
77 RTL_CONSTASCII_USTRINGPARAM((&("/singletons/" "com.sun.star.util.theMacroExpander")[0
]), ((sal_Int32)((sizeof ("/singletons/" "com.sun.star.util.theMacroExpander"
) / sizeof (("/singletons/" "com.sun.star.util.theMacroExpander"
)[0]))-1)), (((rtl_TextEncoding) 11))
78 "/singletons/"(&("/singletons/" "com.sun.star.util.theMacroExpander")[0
]), ((sal_Int32)((sizeof ("/singletons/" "com.sun.star.util.theMacroExpander"
) / sizeof (("/singletons/" "com.sun.star.util.theMacroExpander"
)[0]))-1)), (((rtl_TextEncoding) 11))
79 "com.sun.star.util.theMacroExpander")(&("/singletons/" "com.sun.star.util.theMacroExpander")[0
]), ((sal_Int32)((sizeof ("/singletons/" "com.sun.star.util.theMacroExpander"
) / sizeof (("/singletons/" "com.sun.star.util.theMacroExpander"
)[0]))-1)), (((rtl_TextEncoding) 11))
)),
80 css::uno::UNO_QUERY_THROW);
81 try {
82 url = expUrl->expand(expander);
83 } catch (const css::lang::IllegalArgumentException & e) {
84 throw css::uno::RuntimeException(
85 (::rtl::OUString(
86 RTL_CONSTASCII_USTRINGPARAM((&("com.sun.star.lang.IllegalArgumentException: ")[0]), (
(sal_Int32)((sizeof ("com.sun.star.lang.IllegalArgumentException: "
) / sizeof (("com.sun.star.lang.IllegalArgumentException: ")[
0]))-1)), (((rtl_TextEncoding) 11))
87 "com.sun.star.lang.IllegalArgumentException: ")(&("com.sun.star.lang.IllegalArgumentException: ")[0]), (
(sal_Int32)((sizeof ("com.sun.star.lang.IllegalArgumentException: "
) / sizeof (("com.sun.star.lang.IllegalArgumentException: ")[
0]))-1)), (((rtl_TextEncoding) 11))
)
88 + e.Message),
89 css::uno::Reference< css::uno::XInterface >());
90 }
91 }
92 jvalue arg;
93 arg.l = env->NewString(
94 static_cast< jchar const * >(url.getStr()),
95 static_cast< jsize >(url.getLength()));
96 if (arg.l == 0) {
97 return 0;
98 }
99 jobject o(env->NewObjectA(classUrl, ctorUrl, &arg));
100 if (o == 0) {
101 return 0;
102 }
103 urls.push_back(o);
104 }
105 }
106 jobjectArray result = env->NewObjectArray(
107 static_cast< jsize >(urls.size()), classUrl, 0);
108 // static_cast is ok, as each element of urls occupied at least one
109 // character of the ::rtl::OUString classPath
110 if (result == 0) {
111 return 0;
112 }
113 jsize idx = 0;
114 for (std::vector< jobject >::iterator i(urls.begin()); i != urls.end(); ++i)
115 {
116 env->SetObjectArrayElement(result, idx++, *i);
117 }
118 return result;
119#else
120 (void) context;
121 (void) environment;
122 (void) classPath;
123 return 0;
124#endif
125}
126
127void * ::jvmaccess::ClassPath::doLoadClass(
128 css::uno::Reference< css::uno::XComponentContext > const & context,
129 void * environment, ::rtl::OUString const & classPath,
130 ::rtl::OUString const & name)
131{
132 OSL_ASSERT(context.is() && environment != 0)do { if (true && (!(context.is() && environment
!= 0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), (
"legacy.osl"), ("/usr/local/src/libreoffice/jvmaccess/source/classpath.cxx"
":" "132" ": "), "OSL_ASSERT: %s", "context.is() && environment != 0"
); } } while (false)
;
133#if defined SOLAR_JAVA1
134 ::JNIEnv * const env = static_cast< ::JNIEnv * >(environment);
135 jclass classLoader(env->FindClass("java/net/URLClassLoader"));
136 if (classLoader == 0) {
137 return 0;
138 }
139 jmethodID ctorLoader(
140 env->GetMethodID(classLoader, "<init>", "([Ljava/net/URL;)V"));
141 if (ctorLoader == 0) {
142 return 0;
143 }
144 jvalue arg;
145 arg.l = translateToUrls(context, env, classPath);
146 if (arg.l == 0) {
147 return 0;
148 }
149 jobject cl = env->NewObjectA(classLoader, ctorLoader, &arg);
150 if (cl == 0) {
151 return 0;
152 }
153 jmethodID methLoadClass(
154 env->GetMethodID(
155 classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"));
156 if (methLoadClass == 0) {
157 return 0;
158 }
159 arg.l = env->NewString(
160 static_cast< jchar const * >(name.getStr()),
161 static_cast< jsize >(name.getLength()));
162 if (arg.l == 0) {
163 return 0;
164 }
165 return env->CallObjectMethodA(cl, methLoadClass, &arg);
166#else
167 (void) context;
168 (void) environment;
169 (void) classPath;
170 (void) name;
171 return 0;
172#endif
173}
174
175/* vim:set shiftwidth=4 softtabstop=4 expandtab: */