From 542b0b66560d32817378e0019f696a3cb1523148 Mon Sep 17 00:00:00 2001 From: Sonia Zaldana Calles Date: Tue, 6 Feb 2024 07:03:47 +0000 Subject: [PATCH] 8324126: Error message for mistyping -XX:+Unlock...Options is not helpful Reviewed-by: dholmes, stuefe --- src/hotspot/share/runtime/arguments.cpp | 23 +++++++++---------- .../runtime/CommandLine/TestVMOptions.java | 8 ++++++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index 4f411eb6608..78c26ae57f5 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -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; diff --git a/test/hotspot/jtreg/runtime/CommandLine/TestVMOptions.java b/test/hotspot/jtreg/runtime/CommandLine/TestVMOptions.java index 4ebeb9b7025..a891f9ea530 100644 --- a/test/hotspot/jtreg/runtime/CommandLine/TestVMOptions.java +++ b/test/hotspot/jtreg/runtime/CommandLine/TestVMOptions.java @@ -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'"); } }