SonarQube: Invoke method(s) only conditionally
The call to us.toString()
is redundant, toString()
method will be called regardless the configured log level. You should pass only us
as an argument to info
without an if
statement.
logger.info("Log this: {}", us);
As stated at the comments of the question, another working answer is:
if(logger.isInfoEnabled() && us != null){
logger.info("Log this: {}", us.toString());
}