[Java]String contains no format specifiers. --> what does it mean? How to fix it?

2,357 views
Skip to first unread message

apu...@redhat.com

unread,
Apr 25, 2018, 7:38:53 AM4/25/18
to SonarQube
Hi,

it seems that a new rule is available with latest version.
I have several issue reported as "Printf-style format strings should be used correctly (squid:S3457)"


I don't understand the description and what is wrong in my cases.
There are 2 different cases.
In the rules description we have:
java.util.Logger logger;
logger.log(java.util.logging.Level.SEVERE, "Result {0}.", myObject.toString()); // Noncompliant; no need to call toString() on objects
logger.log(java.util.logging.Level.SEVERE, "Result.", new Exception()); // compliant, parameter is an exception
logger.log(java.util.logging.Level.SEVERE, "Result '{0}'", 14); // Noncompliant {{String contains no format specifiers.}}
and
java.util.Logger logger;
logger.log(java.util.logging.Level.SEVERE, "Result {0}.", myObject);
logger.log(java.util.logging.Level.SEVERE, "Result {0}'", 14);

What's the difference with my cases?
Can you help me understand what is the correct way to write it?

Regards,






apu...@redhat.com

unread,
Apr 25, 2018, 7:43:55 AM4/25/18
to SonarQube
argh realizing that it is recommended to use stackoverflow for this kind of question.

Reply all
Reply to author
Forward
0 new messages