Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update --should-stop=ifError=FLOW flags #4623

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,27 +196,25 @@ private static ImmutableList<String> setCompilePolicyToByFile(ImmutableList<Stri
return ImmutableList.<String>builder().addAll(args).add("-XDcompilePolicy=simple").build();
}

private static void checkShouldStopIfErrorPolicy(String value) {
private static void checkShouldStopIfErrorPolicy(String arg) {
String value = arg.substring(arg.lastIndexOf('=') + 1);
CompileState state = CompileState.valueOf(value);
if (CompileState.FLOW.isAfter(state)) {
throw new InvalidCommandLineOptionException(
String.format(
"-XDshould-stop.ifError=%s is not supported by Error Prone, pass"
+ " -XDshould-stop.ifError=FLOW instead",
state));
"%s is not supported by Error Prone, pass --should-stop=ifError=FLOW instead", arg));
}
}

private static ImmutableList<String> setShouldStopIfErrorPolicyToFlow(
ImmutableList<String> args) {
for (String arg : args) {
if (arg.startsWith("-XDshould-stop.ifError")) {
String value = arg.substring(arg.indexOf('=') + 1);
checkShouldStopIfErrorPolicy(value);
if (arg.startsWith("--should-stop=ifError") || arg.startsWith("-XDshould-stop.ifError")) {
checkShouldStopIfErrorPolicy(arg);
return args; // don't do anything if a valid policy is already set
}
}
return ImmutableList.<String>builder().addAll(args).add("-XDshould-stop.ifError=FLOW").build();
return ImmutableList.<String>builder().addAll(args).add("--should-stop=ifError=FLOW").build();
}

/** Registers our message bundle. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ public void stopPolicy_effectivelyFinal() {
compilerBuilder.report(
ScannerSupplier.fromBugCheckerClasses(EffectivelyFinalChecker.class, CPSChecker.class));
compiler = compilerBuilder.build();
// Without -XDshould-stop.ifError=FLOW, the errors reported by CPSChecker will cause javac to
// Without --should-stop=ifError=FLOW, the errors reported by CPSChecker will cause javac to
// stop processing B after an error is reported in A. Error Prone will still analyze B without
// it having gone through 'flow', and the EFFECTIVELY_FINAL analysis will not have happened.
// see https://github.com/google/error-prone/issues/4595
Expand Down Expand Up @@ -729,7 +729,7 @@ int f(int x) {
public void stopPolicy_flow() {
Result exitCode =
compiler.compile(
new String[] {"-XDshould-stop.ifError=FLOW"},
new String[] {"--should-stop=ifError=FLOW"},
ImmutableList.of(
forSourceLines(
"Test.java",
Expand All @@ -743,6 +743,16 @@ class Test {}

@Test
public void stopPolicy_init() {
InvalidCommandLineOptionException e =
assertThrows(
InvalidCommandLineOptionException.class,
() ->
compiler.compile(new String[] {"--should-stop=ifError=INIT"}, ImmutableList.of()));
assertThat(e).hasMessageThat().contains("--should-stop=ifError=INIT is not supported");
}

@Test
public void stopPolicy_init_xD() {
InvalidCommandLineOptionException e =
assertThrows(
InvalidCommandLineOptionException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public void stopOnErrorPolicy() throws IOException {
ImmutableList.of(
"-Xplugin:ErrorProne",
"-XDcompilePolicy=byfile",
"-XDshould-stop.ifError=LOWER"),
"--should-stop=ifError=LOWER"),
ImmutableList.of(),
fileManager.getJavaFileObjects(one, two));
assertThat(task.call()).isFalse();
Expand Down
Loading