tbroyer / gradle-errorprone-plugin

Gradle plugin to use the error-prone compiler for Java
Apache License 2.0
366 stars 32 forks source link

FormatMethod: about the position of the argument #92

Closed coolderli closed 8 months ago

coolderli commented 8 months ago

I'm using @FormatMethod to format my code. Should the argument be behind the format string?

If I write as below, I will get an error.

@FormatMethod
  public GravitinoRuntimeException(@FormatString String message, Object... args) {
    super(String.format(message, args));
  }

@FormatMethod
public GravitinoRuntimeException(@FormatString String message, Throwable cause, Object... args) {
    super(String.format(message, args), cause);
  }

new GravitinoRuntimeException("Error creating datasource", exception)

The error like:

[FormatStringAnnotation] extra format arguments: used 0, provided 1
tbroyer commented 8 months ago

This message comes from Error Prone and is unrelated to this plugin (on the contrary, it means the plugin correctly did its job, as Error Prone was invoked during compilation).

You'll want to ask on https://groups.google.com/g/error-prone-discuss or https://github.com/google/error-prone/discussions

That being said, I think @FormatMethod expects that all arguments following the @FormatString be format arguments, so you'd have to move the throwable as the first argument in your overloaded constructor.