Inspectopedia Help

Malformed format string

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:

String.format("x = %d, y = %d", 42);

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

MalformedFormatString
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Probable bugs

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:

void myFormatMethod(int mode, @PrintFormat String formatString, Object... args) {...}

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

Inspection options

Here you can find the description of settings available for the Malformed format string inspection, and the reference of their default values.

Additional formatter classes

Empty

Additional formatter methods

Empty

Availability

By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Java, 241.18072

Last modified: 18 June 2024