1

I am using what felt like correct Java code in order to trace sections of a program:

LOG.debug("a simple string with no formatters nor placeholders.");

However, SonarLint in Eclipse is showing the following report on that line:

String contains no format specifiers.

The matching rule, S3457, reads "Printf-style format strings should be used correctly (squid:S3457)".

I am using logback and the LOG variable in the code above is of type org.slf4j.Logger.

I'd like to clear this report, and in the meantime, learn something.

Can someone enlighten me as to what is wrong in this? Or is it a case of Sonar being too strict in applying that rule?

Otherwise, is it considered bad practice to output a log message without outputting values?

AbVog
  • 1,435
  • 22
  • 35
  • 2
    I think this link would be helpful- https://stackoverflow.com/questions/48683723/sonarqube-string-contains-no-format-specifiers-when-logging-constant-string-m – Sourav Ghosh Mar 28 '18 at 13:22

1 Answers1

1

I think this might be an issue with the latest version of SonarQube.

I've found the following report, where the following code produced a false positive of the same issue you encountered:

log.trace("Connection closed");

The SonarQube representative has said that this is a known issue and that they should have a fix ready for it.

Rann Lifshitz
  • 4,040
  • 4
  • 22
  • 42
  • 1
    Thank you. My question is indeed a duplicate as mentioned by someone else and in the other question they refer to, the SonarQube people say the fix is in 6.7 LTS, but I'm running 6.7.1 and I still see this. I'll take it to them. – AbVog Mar 28 '18 at 13:58
  • @AbVog : Happy to help. Love SonarQube/SonarLint. – Rann Lifshitz Mar 28 '18 at 14:06