Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Error Prone Auto-Apply Suggested Fixes?

From what I read about Error Prone, I see that it will actually suggest fixes for style errors in your code. i.e from https://errorprone.info/docs/installation:

ERROR: example/myproject/BUILD:29:1: Java compilation in rule '//example/myproject:hello'
examples/maven/error_prone_should_flag/src/main/java/Main.java:20: error: [DeadException] Exception created but not thrown
    new Exception();
    ^
    (see http://errorprone.info/bugpattern/DeadException)
  Did you mean 'throw new Exception();'?
1 error

What I do not see, is if there is a way to auto-apply these suggested changes. I am running error-prone from the command line. Any and all help is appreciated! Let me know if I can clarify anything.

like image 948
Tyler R Avatar asked Oct 28 '25 14:10

Tyler R


1 Answers

While not currently documented, it is possible to directly apply the suggested changes to the affected source code. One does this by passing -XepPatchLocation:IN_PLACE:

Modifying the original example, the invocation then becomes:

-XepPatchChecks:MissingOverride,DefaultCharset,DeadException
-XepPatchLocation:IN_PLACE

It is strongly recommended to use this feature only when the original file is managed by a version control system. The result can then easily be inspected using e.g. git diff and reverted using e.g. git checkout -- . .

like image 51
Stephan202 Avatar answered Oct 31 '25 02:10

Stephan202



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!