Skip to content

Commit

Permalink
Update --should-stop=ifError=FLOW flags
Browse files Browse the repository at this point in the history
This is equivalent to `-XDshould-stop.ifError=FLOW`, but the `-XD` flag is a
internal javac debug flag interface that writes directly to the options table.
The `--should-stop` flags are slightly more standard.

#4595

PiperOrigin-RevId: 686530096
  • Loading branch information
cushon authored and Error Prone Team committed Oct 16, 2024
1 parent c897d8f commit ca50d5c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
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

0 comments on commit ca50d5c

Please sign in to comment.