Format strings for the printf family of functions must follow the specification in the documentation for java.util.Formatter.
The syntax for format specifiers is:
%[argument_index$][flags][width][.precision]conversion
Format strings can have the following errors:
Duplicate flags are provided in the format specifier:
String.format("e = %++10.4f", Math.E);
A conversion and flag are incompatible:
String.format("%#b", Math.E);
The argument is a character with an invalid Unicode code point.
String.format("%c", 0x110000);
The argument corresponding to the format specifier is of an incompatible type:
String.format("%f", "abcd");
An illegal combination of flags is given:
String.format("%-010d", 5);
The conversion does not support a precision:
String.format("%.c", 'c');
The conversion does not support a width:
String.format("%1n");
There is a format specifier which does not have a corresponding argument or if an argument index refers to an argument that does not exist:
String.format("%<s", "test");
The format width is required:
String.format("e = %-f", Math.E);
An unknown conversion is given:
String.format("%r", "hello");
Suppress false positives by adding the suppression annotation @SuppressWarnings("FormatString")
to the enclosing element.