Skip to content

Commit

Permalink
Reject unrecognized flags that start with -Xep
Browse files Browse the repository at this point in the history
Fixes google#1275

PiperOrigin-RevId: 350823043
  • Loading branch information
cushon authored and stevie400 committed Jan 15, 2021
1 parent 9880adc commit 50f7ecd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
*/
public class ErrorProneOptions {

private static final String PREFIX = "-Xep";
private static final String SEVERITY_PREFIX = "-Xep:";
private static final String PATCH_CHECKS_PREFIX = "-XepPatchChecks:";
private static final String PATCH_OUTPUT_LOCATION = "-XepPatchLocation:";
Expand Down Expand Up @@ -461,6 +462,9 @@ public static ErrorProneOptions processArgs(Iterable<String> args) {
builder.setExcludedPattern(Pattern.compile(pathRegex));

} else {
if (arg.startsWith(PREFIX)) {
throw new InvalidCommandLineOptionException("invalid flag: " + arg);
}
remainingArgs.add(arg);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,11 @@ public void importOrder_androidStaticLast() {
assertThat(options.patchingOptions().importOrganizer())
.isSameInstanceAs(ImportOrganizer.ANDROID_STATIC_LAST_ORGANIZER);
}

@Test
public void noSuchXepFlag() {
assertThrows(
InvalidCommandLineOptionException.class,
() -> ErrorProneOptions.processArgs(new String[] {"-XepNoSuchFlag"}));
}
}

0 comments on commit 50f7ecd

Please sign in to comment.