mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-dfa] containsConstant should ignore locality if values are compared by equals
Fixes IDEA-265089 ConstantCondition always false incorrectly reported on String.equals with String literal on left side GitOrigin-RevId: 4e128a8308a9813bba953e107400c51879a6e7f2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3145faff60
commit
8466dca993
+5
-1
@@ -125,7 +125,11 @@ public interface DfReferenceType extends DfType {
|
||||
|
||||
@Override
|
||||
default boolean containsConstant(@NotNull DfConstantType<?> constant) {
|
||||
return dropTypeConstraint().isSuperType(constant);
|
||||
DfReferenceType filtered = dropTypeConstraint();
|
||||
if (getConstraint().isComparedByEquals()) {
|
||||
filtered = filtered.dropLocality();
|
||||
}
|
||||
return filtered.isSuperType(constant);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
public class StringEqualityNewStringInMethod {
|
||||
// IDEA-265089
|
||||
public boolean bad() {
|
||||
return "baah".equals(toString("baah".getBytes("UTF-8")));
|
||||
}
|
||||
|
||||
public boolean good() {
|
||||
return "baah".equals(new String("baah".getBytes("UTF-8"), 0, 4, "UTF-8"));
|
||||
}
|
||||
|
||||
public boolean good2() {
|
||||
return toString("baah".getBytes("UTF-8")).equals("baah");
|
||||
}
|
||||
|
||||
private static String toString(final byte[] data) {
|
||||
return new String(data, 0, 4, "UTF-8");
|
||||
}
|
||||
}
|
||||
@@ -622,6 +622,7 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
|
||||
public void testVoidIsAlwaysNull() { doTest(); }
|
||||
public void testImpossibleType() { doTest(); }
|
||||
public void testStringEquality() { doTest(); }
|
||||
public void testStringEqualityNewStringInMethod() { doTest(); }
|
||||
public void testAssignmentFieldAliasing() { doTest(); }
|
||||
public void testNewBoxedNumberEquality() { doTest(); }
|
||||
public void testBoxingIncorrectLiteral() { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user