Inspectopedia
 
2024.3

Malformed format string

Warning
New
Last modified: 03 December 2024

Reports format strings that don't comply with the standard Java syntax.

By default, the inspection considers a compile-time constant a format string if it's used as an argument to the corresponding methods on java.util.Formatter, java.lang.String, java.io.PrintWriter or java.io.PrintStream.

Example:

Use the inspection settings to mark additional classes and methods as related to string formatting.

As an alternative, you can use the org.intellij.lang.annotations.PrintFormat annotation to mark the format string method parameter. In this case, the format arguments parameter must immediately follow the format string and be the last method parameter. Example:

Methods annotated in this way will also be recognized by this inspection.