Skip to content
Permalink
Browse files
8266239: Some duplicated javac command-line options have repeated effect
Backport-of: d05494f98bad351532cdb769c9da6b6e2359b16e
  • Loading branch information
lgxbslgx committed Sep 30, 2021
1 parent c26cd97 commit 91dd244f3429449d61677aa9086e13e3498cd0bd
Showing 3 changed files with 41 additions and 2 deletions.
@@ -1154,6 +1154,11 @@ public void handleOption(OptionHelper helper, String arg, Iterator<String> rest)
}
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);
}
}
@@ -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 @@ void testInfoOpt(String opt, String... expect) {
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);
}
}
@@ -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 @@ TestResult checkLog(Log l, String... expects) {
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);
}

1 comment on commit 91dd244

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 91dd244 Sep 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.