Sonarqube,“字符串不包含格式说明符”记录常量String消息时 [英] Sonarqube, "String contains no format specifiers" when logging constant String message

查看:2053
本文介绍了Sonarqube,“字符串不包含格式说明符”记录常量String消息时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.+使用+有效+格式+字符串

但是,在此规则中,我们可以找到以下引用:

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日发布的SonarJava分析器版本 5.1.1 (需要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独立用户更新

对于使用独立版本的SonarLint用户(未连接到任何SonarQube)例如,您可能仍会根据您使用的版本来观察问题。如果您正在使用:

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:


  • 适用于Eclipse 3.5的SonarLint 它包含版本 5.1.0.13090
  • IntelliJ 3.4的SonarLint (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.

这篇关于Sonarqube,“字符串不包含格式说明符”记录常量String消息时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆