S2629 despite using isInfoEnabled

java:S2629 - "Preconditions" and logging arguments should not require evaluation

I call an isInfoEnabled precondition, and yet operations like map.get display this issue.

if (!logger.isInfoEnabled()) {
  return;
}
HashMap<String, String> map = new HashMap<>();
map.put("test", "test");
logger.info("log {}", map.get("test"));
  • logger is public class MyLogger implements org.slf4j.Logger, CustomInterface
  • Library is slf4j-api-2.0.9.jar

image

Hey there, thanks for the report. You are right, the rule should not complain in this case.
We have an existing ticket about a very similar case, so I will add this thread to the ticket.

Have a nice day!

1 Like