8266239: Some duplicated javac command-line options have repeated effect

Reviewed-by: vromero
This commit is contained in:
Guoxiong Li 2021-09-03 09:33:17 +00:00
parent 93eec9a103
commit d05494f98b
3 changed files with 41 additions and 2 deletions

View File

@ -1154,6 +1154,11 @@ public enum Option {
}
process(helper, option, operand);
} else {
if ((this == HELP || this == X || this == HELP_LINT || this == VERSION || this == FULLVERSION)
&& (helper.get(this) != null)) {
// avoid processing the info options repeatedly
return;
}
process(helper, arg);
}
}

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8044859 8230623
* @bug 8044859 8230623 8266239
* @summary test support for info options -help -X -version -fullversion --help-lint
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.file
@ -66,4 +66,22 @@ public class InfoOptsTest extends OptionModesTester {
runParse(opts, files)
.checkIllegalArgumentException();
}
@Test
void testUniqueInfoOpts() throws IOException {
testUniqueInfoOpt(new String[] {"--help", "--help"}, "possible options");
testUniqueInfoOpt(new String[] {"-X", "-X"}, "extra options");
testUniqueInfoOpt(new String[] {"--help-lint", "--help-lint"}, "supported keys");
String specVersion = System.getProperty("java.specification.version");
testUniqueInfoOpt(new String[] {"-version", "-version"}, "javac", specVersion);
testUniqueInfoOpt(new String[] {"-fullversion", "-fullversion"}, "javac", specVersion);
}
void testUniqueInfoOpt(String[] opts, String... expect) {
String[] files = { };
runMain(opts, files)
.checkOK()
.checkUniqueLog(expect);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, 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
@ -269,6 +269,22 @@ public class OptionModesTester {
return this;
}
TestResult checkUniqueLog(String... uniqueExpects) {
return checkUniqueLog(Log.DIRECT, uniqueExpects);
}
TestResult checkUniqueLog(Log l, String... uniqueExpects) {
String log = logs.get(l);
for (String e : uniqueExpects) {
if (!log.contains(e)) {
error("Expected string not found: " + e);
} else if (log.indexOf(e) != log.lastIndexOf(e)) {
error("Expected string appears more than once: " + e);
}
}
return this;
}
TestResult checkIllegalArgumentException() {
return checkThrown(IllegalArgumentException.class);
}