OrphanedFormatString
String literal contains format specifiers, but is not passed to a format method

Severity
WARNING

The problem

Passing a string that contains format specifiers to a method that does not perform string formatting is usually a mistake.

Do this:

if (!isValid(arg)) {
  throw new IllegalArgumentException(String.format("invalid arg: %s", arg));
}

or this:

logger.atWarning().log("invalid arg: %s", arg);

Not this:

if (!isValid(arg)) {
  throw new IllegalArgumentException("invalid arg: %s");
}

or this:

logger.atWarning().log("invalid arg: %s");

If the method you’re calling actually accepts a format string, you can annotate that method with @FormatMethod to ensure that callers correctly pass format strings (and to inform Error Prone that the method call you’re making doesn’t orphan a format string).

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("OrphanedFormatString") to the enclosing element.