8387750: 'java -XshowSettings' alone should not be an error

Reviewed-by: kevinw, alanb
This commit is contained in:
Guanqiang Han 2026-07-22 06:52:47 +00:00 committed by David Holmes
parent 13cb51b07d
commit 68ca4e0f93
3 changed files with 35 additions and 5 deletions

View File

@ -920,10 +920,12 @@ the Java HotSpot Virtual Machine.
: Do not attempt to use shared class data.
[`-XshowSettings`]{#-XshowSettings}
: Shows all settings and then continues.
: Shows all settings and continues. It exits normally if there is no Java
application to launch.
[`-XshowSettings:`]{#-XshowSettings_}*category*
: Shows settings and continues. Possible *category* arguments for this option
: Shows settings and continues. It exits normally if there is no Java
application to launch. Possible *category* arguments for this option
include the following:
`all`

View File

@ -549,6 +549,11 @@ JavaMain(void* _args)
LEAVE();
}
/* Exit normally after showing the settings if no application was specified. */
if (showSettings != NULL && what == NULL) {
LEAVE();
}
FreeKnownVMs(); /* after last possible PrintUsage */
if (JLI_IsTraceLauncher()) {
@ -1351,7 +1356,11 @@ ParseArguments(int *pargc, char ***pargv,
if (*pwhat == NULL) {
/* LM_UNKNOWN okay for options that exit */
if (!listModules && !describeModule && !validateModules && !dumpSharedSpaces) {
if (!listModules &&
!describeModule &&
!validateModules &&
!dumpSharedSpaces &&
!showSettings) {
*pret = 1;
printUsageKind = HELP_CONCISE;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2026, 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
@ -25,7 +25,7 @@ import java.io.IOException;
/*
* @test
* @bug 6994753 7123582 8305950 8281658 8310201 8311653 8343804 8351354 8366364
* @bug 6994753 7123582 8305950 8281658 8310201 8311653 8343804 8351354 8366364 8387750
* @summary tests -XshowSettings options
* @modules jdk.compiler
* jdk.zipfs
@ -86,6 +86,7 @@ public class Settings extends TestHelper {
private static final String ENABLED_GROUPS_SETTINGS = "Enabled Named Groups:";
private static final String ENABLED_SIG_SCHEMES_SETTINGS =
"Enabled Signature Schemes:";
private static final String USAGE_HEADER = "Usage: java";
/*
* "all" should print verbose settings
@ -174,25 +175,32 @@ public class Settings extends TestHelper {
static void runTestOptionAll() throws IOException {
init();
TestResult tr = doExec(javaCmd, "-XshowSettings:all");
tr.checkPositive();
containsAllOptions(tr);
checkNotContains(tr, USAGE_HEADER);
}
static void runTestOptionVM() throws IOException {
TestResult tr = doExec(javaCmd, "-XshowSettings:vm");
tr.checkPositive();
checkContains(tr, VM_SETTINGS);
checkNotContains(tr, PROP_SETTINGS);
checkNotContains(tr, LOCALE_SETTINGS);
checkNotContains(tr, USAGE_HEADER);
}
static void runTestOptionProperty() throws IOException {
TestResult tr = doExec(javaCmd, "-XshowSettings:properties");
tr.checkPositive();
checkNotContains(tr, VM_SETTINGS);
checkContains(tr, PROP_SETTINGS);
checkNotContains(tr, LOCALE_SETTINGS);
checkNotContains(tr, USAGE_HEADER);
}
static void runTestOptionLocale() throws IOException {
TestResult tr = doExec(javaCmd, "-XshowSettings:locale");
tr.checkPositive();
checkNotContains(tr, VM_SETTINGS);
checkNotContains(tr, PROP_SETTINGS);
checkContains(tr, LOCALE_SETTINGS);
@ -200,28 +208,34 @@ public class Settings extends TestHelper {
checkNotContains(tr, LOCALE_SUMMARY_SETTINGS);
checkContains(tr, TIMEZONE_SETTINGS);
checkContains(tr, TZDATA_SETTINGS);
checkNotContains(tr, USAGE_HEADER);
}
static void runTestOptionSecurity() throws IOException {
TestResult tr = doExec(javaCmd, "-XshowSettings:security");
tr.checkPositive();
checkNotContains(tr, VM_SETTINGS);
checkNotContains(tr, PROP_SETTINGS);
checkContains(tr, SEC_PROPS_SETTINGS);
checkContains(tr, SEC_PROVIDER_SETTINGS);
checkContains(tr, SEC_TLS_SETTINGS);
checkNotContains(tr, USAGE_HEADER);
}
static void runTestOptionSecurityProps() throws IOException {
TestResult tr = doExec(javaCmd, "-XshowSettings:security:properties");
tr.checkPositive();
checkContains(tr, SEC_PROPS_SETTINGS);
checkNotContains(tr, SEC_PROVIDER_SETTINGS);
checkNotContains(tr, SEC_TLS_SETTINGS);
// test a well known property for sanity
checkContains(tr, "keystore.type=pkcs12");
checkNotContains(tr, USAGE_HEADER);
}
static void runTestOptionSecurityProv() throws IOException {
TestResult tr = doExec(javaCmd, "-XshowSettings:security:providers");
tr.checkPositive();
checkNotContains(tr, SEC_PROPS_SETTINGS);
checkContains(tr, SEC_PROVIDER_SETTINGS);
checkNotContains(tr, SEC_TLS_SETTINGS);
@ -230,10 +244,12 @@ public class Settings extends TestHelper {
// test for a well known alias (SunJCE: AlgorithmParameterGenerator.DiffieHellman)
checkContains(tr, "aliases: [1.2.840.113549.1.3.1, " +
"DH, OID.1.2.840.113549.1.3.1]");
checkNotContains(tr, USAGE_HEADER);
}
static void runTestOptionSecurityTLS() throws IOException {
TestResult tr = doExec(javaCmd, "-XshowSettings:security:tls");
tr.checkPositive();
checkNotContains(tr, SEC_PROPS_SETTINGS);
checkNotContains(tr, SEC_PROVIDER_SETTINGS);
checkContains(tr, SEC_TLS_SETTINGS);
@ -241,6 +257,7 @@ public class Settings extends TestHelper {
checkContains(tr, "TLSv1.2");
checkContains(tr, ENABLED_GROUPS_SETTINGS);
checkContains(tr, ENABLED_SIG_SCHEMES_SETTINGS);
checkNotContains(tr, USAGE_HEADER);
}
// ensure error message is printed when unrecognized option used
@ -255,6 +272,7 @@ public class Settings extends TestHelper {
}
static void runTestOptionSystem() throws IOException {
TestResult tr = doExec(javaCmd, "-XshowSettings:system");
tr.checkPositive();
if (System.getProperty("os.name").contains("Linux")) {
checkNotContains(tr, VM_SETTINGS);
checkNotContains(tr, PROP_SETTINGS);
@ -266,6 +284,7 @@ public class Settings extends TestHelper {
checkNotContains(tr, VM_SETTINGS);
checkContains(tr, METRICS_NOT_AVAILABLE_MSG);
}
checkNotContains(tr, USAGE_HEADER);
}
static void runTestBadOptions() throws IOException {