Made by DeepSource

Arguments to String.format must match the provided format string JAVA-E1001

Bug risk

String.format accepts arguments based on the content of the format string provided to it. If the format string's specifiers do not match the rest of the arguments provided, String.format will raise an exception at runtime.

Bad Practice

Using the wrong number of parameters as specified by the format string will result in an IllegalFormatException being throwm.

String.format("%d", 1, 2); // Extra parameters.

String.format("%d, %d, %d", 1); // Not enough parameters.


The number and types of format specifiers in the format string must match the provided arguments.

String.format("%d", 1);


This issue will not be thrown when arguments are referred according to index, as it could be that the same argument may be used more than once.