8324126: Error message for mistyping -XX:+Unlock...Options is not helpful

Reviewed-by: dholmes, stuefe
This commit is contained in:
Sonia Zaldana Calles 2024-02-06 07:03:47 +00:00 committed by Thomas Stuefe
parent 9ee9f28849
commit 542b0b6656
2 changed files with 18 additions and 13 deletions

View File

@ -1119,18 +1119,7 @@ bool Arguments::process_argument(const char* arg,
if (found_flag != nullptr) {
char locked_message_buf[BUFLEN];
JVMFlag::MsgType msg_type = found_flag->get_locked_message(locked_message_buf, BUFLEN);
if (strlen(locked_message_buf) == 0) {
if (found_flag->is_bool() && !has_plus_minus) {
jio_fprintf(defaultStream::error_stream(),
"Missing +/- setting for VM option '%s'\n", argname);
} else if (!found_flag->is_bool() && has_plus_minus) {
jio_fprintf(defaultStream::error_stream(),
"Unexpected +/- setting in VM option '%s'\n", argname);
} else {
jio_fprintf(defaultStream::error_stream(),
"Improperly specified VM option '%s'\n", argname);
}
} else {
if (strlen(locked_message_buf) != 0) {
#ifdef PRODUCT
bool mismatched = ((msg_type == JVMFlag::NOTPRODUCT_FLAG_BUT_PRODUCT_BUILD) ||
(msg_type == JVMFlag::DEVELOPER_FLAG_BUT_PRODUCT_BUILD));
@ -1140,6 +1129,16 @@ bool Arguments::process_argument(const char* arg,
#endif
jio_fprintf(defaultStream::error_stream(), "%s", locked_message_buf);
}
if (found_flag->is_bool() && !has_plus_minus) {
jio_fprintf(defaultStream::error_stream(),
"Missing +/- setting for VM option '%s'\n", argname);
} else if (!found_flag->is_bool() && has_plus_minus) {
jio_fprintf(defaultStream::error_stream(),
"Unexpected +/- setting in VM option '%s'\n", argname);
} else {
jio_fprintf(defaultStream::error_stream(),
"Improperly specified VM option '%s'\n", argname);
}
} else {
if (ignore_unrecognized) {
return true;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -59,5 +59,11 @@ public class TestVMOptions {
output = new OutputAnalyzer(pb.start());
output.shouldNotHaveExitValue(0);
output.shouldContain("VM option '-IgnoreUnrecognizedVMOptions'");
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-XX:UnlockExperimentalVMOptions");
output = new OutputAnalyzer(pb.start());
output.stderrShouldContain("VM option 'UnlockExperimentalVMOptions' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.");
output.stderrShouldContain("Missing +/- setting for VM option 'UnlockExperimentalVMOptions'");
}
}