ASSERT-KTH/sorald

Bug in S4973

Closed this issue · 1 comments

Rule S4973 repair can produce NullPointerException. As of now, it does the following repair:

String a = null;
String b = "xyz";

- return a == b;
+ return a.equals(b);

This will result in an NPE during runtime. A better fix would be the following and also suggested by SonarSource.

String a = null;
String b = "xyz";

- return a == b;
+ return a != null a.equals(b);

I personally feel that a better fix would be the usage of Objects.equals(Object, Object) however, this is only valid for Java version >=7. Anyway, we blindly follow SonarSource.

@khaes-kth check this out.