[Sonarqube] [Java] Printf样式的格式字符串应正确使用

Aur*_*ier 2 sonarqube

似乎新规则适用于最新版本。我有几个问题报告为“应正确使用Printf样式的格式字符串(squid:S3457)”

我不了解说明,在我的情况下出了什么问题:

LOGGER.info("Checking for client process pid: {0}", parentProcessId);
// issue: String contains no format specifiers
Run Code Online (Sandbox Code Playgroud)

在规则说明中,我们有:

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.}}
Run Code Online (Sandbox Code Playgroud)

java.util.Logger logger;
logger.log(java.util.logging.Level.SEVERE, "Result {0}.", myObject);
logger.log(java.util.logging.Level.SEVERE, "Result {0}'", 14);
Run Code Online (Sandbox Code Playgroud)

我的案件有什么区别?您能帮我理解什么是正确的书写方式吗?

Aur*_*ier 5

了解我的错误,对于slf4j记录器,需要使用{}而不是{0}