Monits/findbugs-plugin

False positive concatenating strings

Closed this issue · 4 comments

Findbugs reports FB.W.USELESS_STRING_VALUEOF_CALL on this snippet

public void sendMessage(final String msg, final User user) {
    LOGGER.info(msg + " -> " + user.getAccount());
}

Can't reproduce, not even on the same codebase you originally saw this.

Can you consistently reproduce this issue? If so, can you please provide output for:

  • java -version
  • javac -version
  • mvn -version
  • echo $JAVA_HOME

Findbugs reports FB.W.USELESS_STRING_VALUEOF_CALL on a snippet similar to this:

public void myMethod(final String text) {
    new StringBuilder("some text").append(text + " another text ");
}

However, the error disappeared when text became a literal String:

public void myMethod() {
    final String text =  "dummy text";
    new StringBuilder("some text").append(text + " another text ");
}

Here is the info you requested:

  • java -version
    java version "1.8.0_40"
    Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
    Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
  • javac -version
    javac 1.8.0_40
  • mvn -version
    Apache Maven 3.0.5
    Maven home: /usr/share/maven
    Java version: 1.8.0_40, vendor: Oracle Corporation
    Java home: /usr/lib/jvm/jdk1.8.0/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: "linux", version: "3.13.0-62-generic", arch: "amd64", family: "unix"
  • echo $JAVA_HOME
    Didnt print anything.

EDIT: correct code snippet

That's actually a good report. It's useless to do new String("literal string").

Original comment edited.