openrewrite / rewrite-static-analysis

OpenRewrite recipes for identifying and fixing static analysis issues.
Apache License 2.0
30 stars 44 forks source link

Empty arrays and collections should be returned instead of null.`RSPEC-1168` #49

Open yeikel opened 2 years ago

yeikel commented 2 years ago

Possibly dangerous and against "do not harm"


public List<String> getList(){
List<String> l = new ArrayList<>();
l.add("hello");
return l;
}

List<String> l = getList();

if (l == null) {

// will never happen after this transformation

}

https://rules.sonarsource.com/java/quickfix/RSPEC-1168

pway99 commented 2 years ago

yes, lots of potential for a transformation that results in downstream bugs.