RedundantStringOperationInspection: String constructor can be simplified in case the passed array copied entirely

IDEA-226130

GitOrigin-RevId: d20197f50aeceaea2074e905b94ea7d838d53b4a
This commit is contained in:
Andrey Cherkasov
2022-12-15 12:36:23 +04:00
committed by intellij-monorepo-bot
parent f0efafd51c
commit 3ec4cf4a76
4 changed files with 89 additions and 2 deletions

View File

@@ -0,0 +1,17 @@
// "Fix all 'Redundant 'String' operation' problems in file" "true"
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
class Main {
void foo(char[] chars, byte[] bytes, int[] ints) {
String s1 = new String(bytes);
String s2 = new String(chars);
String s3 = new String(bytes, Charset.defaultCharset());
String s4 = new String(bytes, StandardCharsets.ISO_8859_1);
String s5 = new String(ints, 0, ints.length);
String s6 = new String(chars, 0, bytes.length);
String s7 = new String(bytes, 1, bytes.length, Charset.defaultCharset());
String s8 = new String(bytes, 0, bytes.length - 1, StandardCharsets.ISO_8859_1);
}
}

View File

@@ -0,0 +1,17 @@
// "Fix all 'Redundant 'String' operation' problems in file" "true"
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
class Main {
void foo(char[] chars, byte[] bytes, int[] ints) {
String s1 = new String(bytes, 0, bytes.length<caret>);
String s2 = new String(chars, 0, chars.length);
String s3 = new String(bytes, 0, bytes.length, Charset.defaultCharset());
String s4 = new String(bytes, 0, bytes.length, StandardCharsets.ISO_8859_1);
String s5 = new String(ints, 0, ints.length);
String s6 = new String(chars, 0, bytes.length);
String s7 = new String(bytes, 1, bytes.length, Charset.defaultCharset());
String s8 = new String(bytes, 0, bytes.length - 1, StandardCharsets.ISO_8859_1);
}
}