mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 10:20:15 +07:00
StringConcatenationInLoopsInspection: add null-check for unknown variables
IDEA-183139 "String to StringBuilder" quick fix may cause NPE
This commit is contained in:
@@ -5,7 +5,7 @@ public class Main {
|
||||
StringBuilder res = null;
|
||||
for (String s : strings) {
|
||||
if(res == null) {
|
||||
res = new StringBuilder(s);
|
||||
res = s == null ? null : new StringBuilder(s);
|
||||
} else {
|
||||
res.append(s);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Convert variable 'res' from String to StringBuilder" "true"
|
||||
|
||||
public class Main {
|
||||
String test(String[] strings) {
|
||||
StringBuilder res = null;
|
||||
for (String s : strings) {
|
||||
if (s == null) continue;
|
||||
if(res == null) {
|
||||
res = new StringBuilder(s);
|
||||
} else {
|
||||
res.append(s);
|
||||
}
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Convert variable 'res' from String to StringBuilder" "true"
|
||||
|
||||
public class Main {
|
||||
String test(String[] strings) {
|
||||
String res = null;
|
||||
for (String s : strings) {
|
||||
if (s == null) continue;
|
||||
if(res == null) {
|
||||
res = s;
|
||||
} else {
|
||||
res<caret>+=s;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user