Sonarqube,“字符串不包含格式说明符"记录常量字符串消息时
SonarQube 抱怨字符串不包含格式说明符."使用 org.slf4j.Logger
时,特别是方法public void debug(String msg)
".例如
SonarQube complains about "String contains no format specifiers." when using org.slf4j.Logger
, in particular method "public void debug(String msg)
". For example
log.info("message");
参考这条规则:https://wiki.sei.cmu.edu/confluence/display/c/FIO47-C.+Use+valid+format+strings
但是,在这条规则中,我们可以找到以下引用:
However, in this rule, we can find the following quote :
每个转换规范都由 % 字符引入紧随其后(按顺序)
Each conversion specification is introduced by the % character followed (in order) by
零个或多个标志(以任何顺序),它们修改了转换规范
Zero or more flags (in any order), which modify the meaning of the conversion specification
是我遗漏了什么,还是这条规则没有很好地执行?有这方面的经验吗?
Is it me that miss something, or is this rule not well implemented? Any experience with that ?
推荐答案
这是 SonarJava 5.1 引入的一个已知问题.您可以放心地将此问题视为误报 (FP) 和/或忽略它.在处理 JIRA 票证 SONARJAVA-2633 时已修复此问题.
This is a known issue introduced with SonarJava 5.1. You can safely consider this issue as a False Positive (FP) and/or ignore it. It has already been fixed while handling JIRA ticket SONARJAVA-2633.
该修复程序已与 2018 年 2 月 16 日发布的 5.1.1 版 SonarJava 分析器一起提供(需要 SonarQube LTS 6.7 或更高版本).
The fix has been delivered with version 5.1.1 of SonarJava analyzer, released on Feb 16, 2018 (requires SonarQube LTS 6.7 or superior).
SonarLint 独立用户更新
对于使用独立版本(未连接到任何 SonarQube 实例)的 SonarLint 用户,您可能仍会根据所使用的版本观察到问题.如果您正在使用:
For SonarLint users working with standalone versions (not connected to any SonarQube instance), you may still observe the issue depending of the version you are using. If you are using:
- SonarLint for Eclipse 3.5:它包含 SonarJava 的 5.1.0.13090 版本,因此您仍会在代码中观察到 FP.下一个版本将使用更新版本的 SonarJava,从而解决该问题.下一版本预计将于 2018 年 5 月底/6 月初发布.
- SonarLint for IntelliJ 3.4(2018 年 5 月 9 日发布):包含 SonarJava 5.3.0.13828,表示该问题已修复.将您的版本更新到最新发布的版本应该可以解决该问题.
- SonarLint for Eclipse 3.5: It includes version 5.1.0.13090 of SonarJava, so you will still observe the FP on your code. Next release will use a more recent version of SonarJava, therefore resolving the issue. Next version is expected for end of May/early June 2018.
- SonarLint for IntelliJ 3.4 (released on May 9, 2018): It includes SonarJava 5.3.0.13828, which means that the issue has been fixed. Updating your version to latest released version should then fix the issue.
相关文章