author | rriggs |
Fri, 09 Nov 2018 13:28:16 -0500 | |
changeset 52478 | b915bd68d907 |
parent 48027 | ddbcfca4d51d |
permissions | -rw-r--r-- |
2 | 1 |
/* |
48027
ddbcfca4d51d
8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include "jni.h" |
|
27 |
#include "jni_util.h" |
|
28 |
#include "jvm.h" |
|
29 |
||
30 |
#include "java_lang_SecurityManager.h" |
|
31 |
#include "java_lang_ClassLoader.h" |
|
32 |
||
33 |
/* |
|
34 |
* Make sure a security manager instance is initialized. |
|
35 |
* TRUE means OK, FALSE means not. |
|
36 |
*/ |
|
37 |
static jboolean |
|
38 |
check(JNIEnv *env, jobject this) |
|
39 |
{ |
|
40 |
static jfieldID initField = 0; |
|
41 |
jboolean initialized = JNI_FALSE; |
|
42 |
||
43 |
if (initField == 0) { |
|
44 |
jclass clazz = (*env)->FindClass(env, "java/lang/SecurityManager"); |
|
45 |
if (clazz == 0) { |
|
46 |
(*env)->ExceptionClear(env); |
|
47 |
return JNI_FALSE; |
|
48 |
} |
|
49 |
initField = (*env)->GetFieldID(env, clazz, "initialized", "Z"); |
|
50 |
if (initField == 0) { |
|
51 |
(*env)->ExceptionClear(env); |
|
52 |
return JNI_FALSE; |
|
53 |
} |
|
54 |
} |
|
55 |
initialized = (*env)->GetBooleanField(env, this, initField); |
|
56 |
||
57 |
if (initialized == JNI_TRUE) { |
|
58 |
return JNI_TRUE; |
|
59 |
} else { |
|
60 |
jclass securityException = |
|
61 |
(*env)->FindClass(env, "java/lang/SecurityException"); |
|
62 |
if (securityException != 0) { |
|
63 |
(*env)->ThrowNew(env, securityException, |
|
64 |
"security manager not initialized."); |
|
65 |
} |
|
66 |
return JNI_FALSE; |
|
67 |
} |
|
68 |
} |
|
69 |
||
70 |
JNIEXPORT jobjectArray JNICALL |
|
71 |
Java_java_lang_SecurityManager_getClassContext(JNIEnv *env, jobject this) |
|
72 |
{ |
|
73 |
if (!check(env, this)) { |
|
74 |
return NULL; /* exception */ |
|
75 |
} |
|
76 |
||
77 |
return JVM_GetClassContext(env); |
|
78 |
} |