Skip to content

Commit ca50d5c

Browse files
cushonError Prone Team
authored and
Error Prone Team
committed
Update --should-stop=ifError=FLOW flags
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
1 parent c897d8f commit ca50d5c

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

check_api/src/main/java/com/google/errorprone/BaseErrorProneJavaCompiler.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,27 +196,25 @@ private static ImmutableList<String> setCompilePolicyToByFile(ImmutableList<Stri
196196
return ImmutableList.<String>builder().addAll(args).add("-XDcompilePolicy=simple").build();
197197
}
198198

199-
private static void checkShouldStopIfErrorPolicy(String value) {
199+
private static void checkShouldStopIfErrorPolicy(String arg) {
200+
String value = arg.substring(arg.lastIndexOf('=') + 1);
200201
CompileState state = CompileState.valueOf(value);
201202
if (CompileState.FLOW.isAfter(state)) {
202203
throw new InvalidCommandLineOptionException(
203204
String.format(
204-
"-XDshould-stop.ifError=%s is not supported by Error Prone, pass"
205-
+ " -XDshould-stop.ifError=FLOW instead",
206-
state));
205+
"%s is not supported by Error Prone, pass --should-stop=ifError=FLOW instead", arg));
207206
}
208207
}
209208

210209
private static ImmutableList<String> setShouldStopIfErrorPolicyToFlow(
211210
ImmutableList<String> args) {
212211
for (String arg : args) {
213-
if (arg.startsWith("-XDshould-stop.ifError")) {
214-
String value = arg.substring(arg.indexOf('=') + 1);
215-
checkShouldStopIfErrorPolicy(value);
212+
if (arg.startsWith("--should-stop=ifError") || arg.startsWith("-XDshould-stop.ifError")) {
213+
checkShouldStopIfErrorPolicy(arg);
216214
return args; // don't do anything if a valid policy is already set
217215
}
218216
}
219-
return ImmutableList.<String>builder().addAll(args).add("-XDshould-stop.ifError=FLOW").build();
217+
return ImmutableList.<String>builder().addAll(args).add("--should-stop=ifError=FLOW").build();
220218
}
221219

222220
/** Registers our message bundle. */

core/src/test/java/com/google/errorprone/ErrorProneCompilerIntegrationTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ public void stopPolicy_effectivelyFinal() {
689689
compilerBuilder.report(
690690
ScannerSupplier.fromBugCheckerClasses(EffectivelyFinalChecker.class, CPSChecker.class));
691691
compiler = compilerBuilder.build();
692-
// Without -XDshould-stop.ifError=FLOW, the errors reported by CPSChecker will cause javac to
692+
// Without --should-stop=ifError=FLOW, the errors reported by CPSChecker will cause javac to
693693
// stop processing B after an error is reported in A. Error Prone will still analyze B without
694694
// it having gone through 'flow', and the EFFECTIVELY_FINAL analysis will not have happened.
695695
// see https://github.com/google/error-prone/issues/4595
@@ -729,7 +729,7 @@ int f(int x) {
729729
public void stopPolicy_flow() {
730730
Result exitCode =
731731
compiler.compile(
732-
new String[] {"-XDshould-stop.ifError=FLOW"},
732+
new String[] {"--should-stop=ifError=FLOW"},
733733
ImmutableList.of(
734734
forSourceLines(
735735
"Test.java",
@@ -743,6 +743,16 @@ class Test {}
743743

744744
@Test
745745
public void stopPolicy_init() {
746+
InvalidCommandLineOptionException e =
747+
assertThrows(
748+
InvalidCommandLineOptionException.class,
749+
() ->
750+
compiler.compile(new String[] {"--should-stop=ifError=INIT"}, ImmutableList.of()));
751+
assertThat(e).hasMessageThat().contains("--should-stop=ifError=INIT is not supported");
752+
}
753+
754+
@Test
755+
public void stopPolicy_init_xD() {
746756
InvalidCommandLineOptionException e =
747757
assertThrows(
748758
InvalidCommandLineOptionException.class,

core/src/test/java/com/google/errorprone/ErrorProneJavacPluginTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public void stopOnErrorPolicy() throws IOException {
304304
ImmutableList.of(
305305
"-Xplugin:ErrorProne",
306306
"-XDcompilePolicy=byfile",
307-
"-XDshould-stop.ifError=LOWER"),
307+
"--should-stop=ifError=LOWER"),
308308
ImmutableList.of(),
309309
fileManager.getJavaFileObjects(one, two));
310310
assertThat(task.call()).isFalse();

0 commit comments

Comments
 (0)