author | stuefe |
Thu, 04 Jul 2019 11:55:00 +0200 | |
changeset 55695 | 7eb1f8d4a4e9 |
parent 54446 | b16e8a886fc3 |
permissions | -rw-r--r-- |
54446
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
1 |
/* |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
4 |
* |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
8 |
* |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
13 |
* accompanied this code). |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
14 |
* |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
18 |
* |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
21 |
* questions. |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
22 |
* |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
23 |
*/ |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
24 |
|
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
25 |
/** |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
26 |
* @test |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
27 |
* @bug 8221530 |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
28 |
* @summary Test uses custom launcher that starts VM using JNI that verifies |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
29 |
* reflection API with null caller class |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
30 |
* @library /test/lib |
55695
7eb1f8d4a4e9
8227252: [aix] Disable jdk/java/lang/reflect/exeCallerAccessTest
stuefe
parents:
54446
diff
changeset
|
31 |
* @requires os.family != "aix" |
54446
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
32 |
* @run main/native CallerAccessTest |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
33 |
*/ |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
34 |
|
55695
7eb1f8d4a4e9
8227252: [aix] Disable jdk/java/lang/reflect/exeCallerAccessTest
stuefe
parents:
54446
diff
changeset
|
35 |
// Test disabled on AIX since we cannot invoke the JVM on the primordial thread. |
7eb1f8d4a4e9
8227252: [aix] Disable jdk/java/lang/reflect/exeCallerAccessTest
stuefe
parents:
54446
diff
changeset
|
36 |
|
54446
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
37 |
import java.io.File; |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
38 |
import java.util.Map; |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
39 |
import jdk.test.lib.Platform; |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
40 |
import jdk.test.lib.Utils; |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
41 |
import jdk.test.lib.process.OutputAnalyzer; |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
42 |
|
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
43 |
import java.io.IOException; |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
44 |
import java.nio.file.Path; |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
45 |
import java.nio.file.Paths; |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
46 |
|
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
47 |
public class CallerAccessTest { |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
48 |
public static void main(String[] args) throws IOException { |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
49 |
Path launcher = Paths.get(System.getProperty("test.nativepath"), "CallerAccessTest"); |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
50 |
ProcessBuilder pb = new ProcessBuilder(launcher.toString()); |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
51 |
Map<String, String> env = pb.environment(); |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
52 |
|
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
53 |
String libName = Platform.isWindows() ? "bin" : "lib"; |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
54 |
Path libPath = Paths.get(Utils.TEST_JDK).resolve(libName); |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
55 |
String libDir = libPath.toAbsolutePath().toString(); |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
56 |
String serverDir = libPath.resolve("server").toAbsolutePath().toString(); |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
57 |
|
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
58 |
// set up shared library path |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
59 |
String sharedLibraryPathEnvName = Platform.sharedLibraryPathVariableName(); |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
60 |
env.compute(sharedLibraryPathEnvName, |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
61 |
(k, v) -> (v == null) ? libDir : v + File.pathSeparator + libDir); |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
62 |
env.compute(sharedLibraryPathEnvName, |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
63 |
(k, v) -> (v == null) ? serverDir : v + File.pathSeparator + serverDir); |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
64 |
|
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
65 |
System.out.println("Launching: " + launcher + " shared library path: " + |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
66 |
env.get(sharedLibraryPathEnvName)); |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
67 |
new OutputAnalyzer(pb.start()).shouldHaveExitValue(0); |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
68 |
} |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
69 |
} |
b16e8a886fc3
8221530: Caller sensitive methods not handling caller = null when invoked by JNI code with no java frames on stack
mchung
parents:
diff
changeset
|
70 |