Logging exception example violates different rule

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarLint 8.2.0.68615
  • how is SonarQube deployed: zip, Docker, Helm
    n/a
  • what are you trying to achieve
    n/a
  • what have you tried so far to achieve this
    n/a

For rule "Preconditions" and logging arguments should not require evaluation java:S2629 one of the examples of compliant solutions is:
LOG.error("Unable to open file {0}", csvPath, e);
But using such violates different rule Printf-style format strings should be used correctly java:S3457.

If I understand it correctly, it should be:
LOG.error(new ParameterizedMessage("Unable to open file {}", csvPath), e);

Hi Wojteo, welcome to the community!

What is LOG in your case? This problem has already been fixed in 2020 (see SONARJAVA-3044), but only specifically for these two logging libraries:

  • org.slf4j.Logger
  • java.util.logging.Logger

I suppose you are using another library?

Cheers,

Marco

Hi,

I am using org.apache.logging.log4j » log4j-core » 2.X

Thanks Wojteo!

I created a ticket to include it in the list of exceptions.

Cheers,
Marco