mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-08 20:49:44 +00:00
8175055: Errors reported by Arguments.validate should (probably) be fatal
Reviewed-by: jjg
This commit is contained in:
parent
8ef02f7acc
commit
b320d61bdb
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2017, 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
|
||||
@ -421,9 +421,7 @@ public class Start extends ToolOption.Helper {
|
||||
|
||||
Result result = OK;
|
||||
try {
|
||||
result = parseAndExecute(options, fileObjects)
|
||||
? OK
|
||||
: ERROR;
|
||||
result = parseAndExecute(options, fileObjects);
|
||||
} catch (com.sun.tools.javac.main.Option.InvalidValueException e) {
|
||||
messager.printError(e.getMessage());
|
||||
Throwable t = e.getCause();
|
||||
@ -501,7 +499,7 @@ public class Start extends ToolOption.Helper {
|
||||
* Main program - internal
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private boolean parseAndExecute(List<String> argList, Iterable<? extends JavaFileObject> fileObjects)
|
||||
private Result parseAndExecute(List<String> argList, Iterable<? extends JavaFileObject> fileObjects)
|
||||
throws ToolException, OptionException, com.sun.tools.javac.main.Option.InvalidValueException {
|
||||
long tm = System.currentTimeMillis();
|
||||
|
||||
@ -521,7 +519,14 @@ public class Start extends ToolOption.Helper {
|
||||
Arguments arguments = Arguments.instance(context);
|
||||
arguments.init(ProgramName);
|
||||
arguments.allowEmpty();
|
||||
arguments.validate();
|
||||
if (!arguments.validate()) {
|
||||
// Arguments does not always increase the error count in the
|
||||
// case of errors, so increment the error count only if it has
|
||||
// not been updated previously, preventing complaints by callers
|
||||
if (!messager.hasErrors() && !messager.hasWarnings())
|
||||
messager.nerrors++;
|
||||
return CMDERR;
|
||||
}
|
||||
|
||||
if (fileManager instanceof BaseFileManager) {
|
||||
((BaseFileManager) fileManager).handleOptions(fileManagerOpts);
|
||||
@ -586,7 +591,7 @@ public class Start extends ToolOption.Helper {
|
||||
}
|
||||
|
||||
JavadocTool comp = JavadocTool.make0(context);
|
||||
if (comp == null) return false;
|
||||
if (comp == null) return ABNORMAL;
|
||||
|
||||
DocletEnvironment docEnv = comp.getEnvironment(jdtoolOpts,
|
||||
javaNames,
|
||||
@ -600,8 +605,9 @@ public class Start extends ToolOption.Helper {
|
||||
trees.setBreakIterator(BreakIterator.getSentenceInstance(locale));
|
||||
}
|
||||
// pass off control to the doclet
|
||||
boolean ok = docEnv != null;
|
||||
if (ok) ok = doclet.run(docEnv);
|
||||
Result returnStatus = docEnv != null && doclet.run(docEnv)
|
||||
? OK
|
||||
: ERROR;
|
||||
|
||||
// We're done.
|
||||
if (compOpts.get("-verbose") != null) {
|
||||
@ -609,7 +615,7 @@ public class Start extends ToolOption.Helper {
|
||||
messager.notice("main.done_in", Long.toString(tm));
|
||||
}
|
||||
|
||||
return ok;
|
||||
return returnStatus;
|
||||
}
|
||||
|
||||
boolean matches(List<String> names, String arg) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2017, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4934778 4777599 6553182 8146427 8146475
|
||||
* @bug 4934778 4777599 6553182 8146427 8146475 8175055
|
||||
* @summary Make sure that -help, -helpfile and -nohelp options work correctly.
|
||||
* @author jamieh
|
||||
* @library ../lib
|
||||
@ -111,7 +111,7 @@ public class TestHelpOption extends JavadocTester {
|
||||
"-helpfile", testSrc("test-help.html"),
|
||||
"-helpfile", testSrc("test-help.html"),
|
||||
testSrc("Sample.java"));
|
||||
checkExit(Exit.ERROR);
|
||||
checkExit(Exit.CMDERR);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -121,7 +121,7 @@ public class TestHelpOption extends JavadocTester {
|
||||
"-helpfile", testSrc("test-help.html"),
|
||||
"-nohelp",
|
||||
testSrc("Sample.java"));
|
||||
checkExit(Exit.ERROR);
|
||||
checkExit(Exit.CMDERR);
|
||||
}
|
||||
|
||||
private void checkOutput(boolean withOption) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2017, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8169676
|
||||
* @bug 8169676 8175055
|
||||
* @summary boolean result of Option.process is often ignored
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* @modules jdk.compiler/com.sun.tools.javac.main
|
||||
@ -37,20 +37,6 @@
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.lang.model.SourceVersion;
|
||||
|
||||
import jdk.javadoc.doclet.Doclet;
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
import jdk.javadoc.doclet.Reporter;
|
||||
|
||||
import toolbox.JavadocTask;
|
||||
import toolbox.ModuleBuilder;
|
||||
@ -146,6 +132,25 @@ public class BadOptionsTest extends TestRunner {
|
||||
checkNotFound(result, "Exception", "at jdk.javadoc/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSourcePathAndModuleSourceConflict() throws IOException {
|
||||
Path msrc = Paths.get("msrc");
|
||||
new ModuleBuilder(tb, "m1")
|
||||
.exports("p1")
|
||||
.classes("package p1; public class C1 { }")
|
||||
.write(msrc);
|
||||
Task.Result result = new JavadocTask(tb, Task.Mode.CMDLINE)
|
||||
.options("-sourcepath", "src",
|
||||
"--module-source-path", msrc.getFileName().toString(),
|
||||
"--module", "m1")
|
||||
.run(Task.Expect.FAIL)
|
||||
.writeAll();
|
||||
checkFound(result.getOutput(Task.OutputKind.DIRECT),
|
||||
"javadoc: cannot specify both --source-path and --module-source-path");
|
||||
checkFound(result.getOutput(Task.OutputKind.DIRECT),
|
||||
"1 error");
|
||||
}
|
||||
|
||||
private void checkFound(String log, String... expect) {
|
||||
for (String e : expect) {
|
||||
if (!log.contains(e)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user