Skip to content

Commit c08b2ac

Browse files
author
Harold Seigel
committedJan 11, 2022
8225093: Special property jdk.boot.class.path.append should not default to empty string
Reviewed-by: dholmes, sspitsyn, alanb
1 parent 4c52eb3 commit c08b2ac

File tree

4 files changed

+118
-2
lines changed

4 files changed

+118
-2
lines changed
 

‎src/hotspot/share/runtime/arguments.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void Arguments::init_system_properties() {
412412
// It can only be set by either:
413413
// - -Xbootclasspath/a:
414414
// - AddToBootstrapClassLoaderSearch during JVMTI OnLoad phase
415-
_jdk_boot_class_path_append = new SystemProperty("jdk.boot.class.path.append", "", false, true);
415+
_jdk_boot_class_path_append = new SystemProperty("jdk.boot.class.path.append", NULL, false, true);
416416

417417
// Add to System Property list.
418418
PropertyList_add(&_system_properties, _sun_boot_library_path);

‎src/hotspot/share/runtime/arguments.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ class SystemProperty : public PathString {
109109
void set_next(SystemProperty* next) { _next = next; }
110110

111111
bool is_readable() const {
112-
return !_internal || strcmp(_key, "jdk.boot.class.path.append") == 0;
112+
return !_internal || (strcmp(_key, "jdk.boot.class.path.append") == 0 &&
113+
value() != NULL);
113114
}
114115

115116
// A system property should only have its value set
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
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
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @bug 8225093
27+
* @summary Check that JVMTI GetSystemProperty API returns the right values for
28+
* property jdk.boot.class.path.append.
29+
* @requires vm.jvmti
30+
* @library /test/lib
31+
* @run main/othervm/native -agentlib:GetBootClassPathAppendProp GetBootClassPathAppendProp
32+
* @run main/othervm/native -Xbootclasspath/a:blah -agentlib:GetBootClassPathAppendProp GetBootClassPathAppendProp one_arg
33+
*
34+
*/
35+
36+
public class GetBootClassPathAppendProp {
37+
private static native String getSystemProperty();
38+
39+
public static void main(String[] args) throws Exception {
40+
String path = getSystemProperty();
41+
if (args.length > 0) {
42+
if (!path.equals("blah")) {
43+
throw new RuntimeException("Wrong value returned for jdk.boot.class.path.append: " +
44+
path);
45+
}
46+
} else {
47+
if (path != null) {
48+
throw new RuntimeException("Null value expected for jdk.boot.class.path.append: " +
49+
path);
50+
}
51+
}
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
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
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
#include <stdio.h>
25+
#include <string.h>
26+
#include <jvmti.h>
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
static jvmtiEnv *jvmti = NULL;
33+
34+
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
35+
int err = (*jvm)->GetEnv(jvm, (void**) &jvmti, JVMTI_VERSION_9);
36+
if (err != JNI_OK) {
37+
return JNI_ERR;
38+
}
39+
return JNI_OK;
40+
}
41+
42+
JNIEXPORT jstring JNICALL
43+
Java_GetBootClassPathAppendProp_getSystemProperty(JNIEnv *env, jclass cls) {
44+
jvmtiError err;
45+
char* prop_value;
46+
47+
err = (*jvmti)->GetSystemProperty(jvmti, "jdk.boot.class.path.append", &prop_value);
48+
if (err == JVMTI_ERROR_NOT_AVAILABLE) {
49+
return NULL;
50+
}
51+
if (err != JVMTI_ERROR_NONE) {
52+
char err_msg[50];
53+
snprintf(err_msg, 50, "Wrong JVM TI error code: %d", err);
54+
return (*env)->NewStringUTF(env, err_msg);
55+
}
56+
57+
return (*env)->NewStringUTF(env, prop_value);
58+
}
59+
60+
#ifdef __cplusplus
61+
}
62+
#endif

0 commit comments

Comments
 (0)