[java-dfa] IDEA-373973 Wrong inspection on String.isEmpty()

GitOrigin-RevId: a17fb96e3e4f9a7f23bdeb8be51c1bc16ff478fa
This commit is contained in:
Tagir Valeev
2025-07-21 10:14:00 +00:00
committed by intellij-monorepo-bot
parent 0cc6334ad9
commit e294c2f5c9
2 changed files with 13 additions and 3 deletions
@@ -6,7 +6,7 @@ class Test {
int pos = s.indexOf('x');
if (<warning descr="Condition 'pos < s.length()' is always 'true'">pos < s.length()</warning>) {}
int pos2 = s.indexOf(s1);
if (<warning descr="Condition 'pos2 < s.length()' is always 'true'">pos2 < s.length()</warning>) {}
if (pos2 < s.length()) {}
int pos3 = s.lastIndexOf('x');
if (<warning descr="Condition 'pos3 < s.length()' is always 'true'">pos3 < s.length()</warning>) {}
int pos4 = s.lastIndexOf("xyz");
@@ -21,4 +21,14 @@ class Test {
}
int max = Math.<warning descr="Result of 'max' is the same as the first argument making the call meaningless">max</warning>(s.length(), s.indexOf('a'));
}
private static void foo(String text) {
String s = "";
int idx = text.indexOf(s);
if (idx < 0) {
return;
}
String text1 = text.substring(idx);
System.out.println(text1.isEmpty());
}
}