Inspectopedia Help

Invalid format string

Invalid format string

If a string contains a '%' character, then the string may be a formatting string which will be passed to String.format from Java code to replace each '%' occurrence with specific values.

This lint warning checks for two related problems:

(1) Formatting strings that are invalid, meaning that String.format will throw exceptions at runtime when attempting to use the format string.

(2) Strings containing '%' that are not formatting strings getting passed to a String.format call. In this case the '%' will need to be escaped as '%%'.

NOTE: Not all Strings which look like formatting strings are intended for use by String.format; for example, they may contain date formats intended for android.text.format.Time#format(). Lint cannot always figure out that a String is a date format, so you may get false warnings in those scenarios. See the suppress help topic for information on how to suppress errors in that case.

Issue id: StringFormatInvalid

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for Android 2023.3, Qodana for JVM 2023.3

Plugin:

Android, 2022.3.1 Beta 2

Last modified: 13 July 2023