Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/stringConcatInLoop/afterConcatNullSafe.java
Tagir Valeev 2e7492686e StringConcatenationInLoopsInspection: null-safe fixes
Fixes IDEA-183139 "String to StringBuilder" quick fix may cause NPE
2017-12-26 17:18:40 +07:00

16 lines
424 B
Java

// "Convert variable 'res' from String to StringBuilder (null-safe)" "true"
class Main {
String test(String[] strings) {
StringBuilder res = null;
for (String s : strings) {
if(res == null) {
res = s == null ? null : new StringBuilder(s);
} else {
res.append(s);
}
}
return res == null ? null : res.toString();
}
}