Sonarqube, “String contains no format specifiers” when logging constant String message

后端 未结 2 599
星月不相逢
星月不相逢 2021-01-03 19:57

SonarQube complains about \"String contains no format specifiers.\" when using org.slf4j.Logger, in particular method \"public void debug(String

相关标签:
2条回答
  • 2021-01-03 20:36

    Noncompliant Code Example

    logger.info("Query: " , query);
    LOGGER.info("Query: {0}", query);
    // issue: String contains no format specifiers
    LOGGER.info("Query: {0}", query);
    // issue: String contains no format specifiers
    

    Compliant Solution

    LOGGER.info("Query: {}", query);
    
    0 讨论(0)
  • 2021-01-03 20:44

    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.

    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).

    Update for SonarLint standalone users

    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: 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.
    0 讨论(0)
提交回复
热议问题