[java-inspection] StringConcatenationInLoops preview-friendly & fixed toString in null-safe mode

GitOrigin-RevId: b545a5a7acb3daa45b6aa4f675c819fefd70c350
This commit is contained in:
Tagir Valeev
2020-08-03 15:50:45 +07:00
committed by intellij-monorepo-bot
parent 9ca4341d7f
commit fcec11b91c
3 changed files with 72 additions and 22 deletions

View File

@@ -0,0 +1,18 @@
// "Introduce new StringBuilder to update variable 'res' (null-safe)" "true"
public class SB {
public static void main(String[] args) {
StringBuilder resBuilder = null;
for (String arg : args) {
if (resBuilder == null) {
resBuilder = new StringBuilder("[");
} else {
resBuilder.append(",");
}
resBuilder.append(arg);
}
String res = String.valueOf(resBuilder);
res += "]";
System.out.println(res);
}
}

View File

@@ -0,0 +1,17 @@
// "Introduce new StringBuilder to update variable 'res' (null-safe)" "true"
public class SB {
public static void main(String[] args) {
String res = null;
for (String arg : args) {
if (res == null) {
res = "[";
} else {
res +<caret>= ",";
}
res += arg;
}
res += "]";
System.out.println(res);
}
}