Sonar smells Java code wrongly for String concatenation

https://rules.sonarsource.com/java/tag/performance/RSPEC-1643

String text = “Hello” + “World”;

Sonar smells the above line. However, Java compiler converts this to (new StringBuilder()).append(“Hello”).append(“World”).toString();
I agree with you if we are placing the code in for loop. But in this case, it should not throw any alarm.

Can you please verify this.

Hello @Pavan

I’m not sure to understand, the code you provided does not raise any issue on my side.

Are you sure you did not oversimplified the example?