Skip to content

Commit 542b0b6

Browse files
Sonia Zaldana Calleststuefe
Sonia Zaldana Calles
authored andcommittedFeb 6, 2024
8324126: Error message for mistyping -XX:+Unlock...Options is not helpful
Reviewed-by: dholmes, stuefe
1 parent 9ee9f28 commit 542b0b6

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed
 

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

+11-12
Original file line numberDiff line numberDiff line change
@@ -1119,18 +1119,7 @@ bool Arguments::process_argument(const char* arg,
11191119
if (found_flag != nullptr) {
11201120
char locked_message_buf[BUFLEN];
11211121
JVMFlag::MsgType msg_type = found_flag->get_locked_message(locked_message_buf, BUFLEN);
1122-
if (strlen(locked_message_buf) == 0) {
1123-
if (found_flag->is_bool() && !has_plus_minus) {
1124-
jio_fprintf(defaultStream::error_stream(),
1125-
"Missing +/- setting for VM option '%s'\n", argname);
1126-
} else if (!found_flag->is_bool() && has_plus_minus) {
1127-
jio_fprintf(defaultStream::error_stream(),
1128-
"Unexpected +/- setting in VM option '%s'\n", argname);
1129-
} else {
1130-
jio_fprintf(defaultStream::error_stream(),
1131-
"Improperly specified VM option '%s'\n", argname);
1132-
}
1133-
} else {
1122+
if (strlen(locked_message_buf) != 0) {
11341123
#ifdef PRODUCT
11351124
bool mismatched = ((msg_type == JVMFlag::NOTPRODUCT_FLAG_BUT_PRODUCT_BUILD) ||
11361125
(msg_type == JVMFlag::DEVELOPER_FLAG_BUT_PRODUCT_BUILD));
@@ -1140,6 +1129,16 @@ bool Arguments::process_argument(const char* arg,
11401129
#endif
11411130
jio_fprintf(defaultStream::error_stream(), "%s", locked_message_buf);
11421131
}
1132+
if (found_flag->is_bool() && !has_plus_minus) {
1133+
jio_fprintf(defaultStream::error_stream(),
1134+
"Missing +/- setting for VM option '%s'\n", argname);
1135+
} else if (!found_flag->is_bool() && has_plus_minus) {
1136+
jio_fprintf(defaultStream::error_stream(),
1137+
"Unexpected +/- setting in VM option '%s'\n", argname);
1138+
} else {
1139+
jio_fprintf(defaultStream::error_stream(),
1140+
"Improperly specified VM option '%s'\n", argname);
1141+
}
11431142
} else {
11441143
if (ignore_unrecognized) {
11451144
return true;

‎test/hotspot/jtreg/runtime/CommandLine/TestVMOptions.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -59,5 +59,11 @@ public static void main(String[] args) throws Exception {
5959
output = new OutputAnalyzer(pb.start());
6060
output.shouldNotHaveExitValue(0);
6161
output.shouldContain("VM option '-IgnoreUnrecognizedVMOptions'");
62+
63+
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
64+
"-XX:UnlockExperimentalVMOptions");
65+
output = new OutputAnalyzer(pb.start());
66+
output.stderrShouldContain("VM option 'UnlockExperimentalVMOptions' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.");
67+
output.stderrShouldContain("Missing +/- setting for VM option 'UnlockExperimentalVMOptions'");
6268
}
6369
}

0 commit comments

Comments
 (0)
Please sign in to comment.