mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-dfa] Preserve accessor as variable having Optional.get as qualifier
IDEA-276924 Incorrect ConstantConditions inspection warning in combination with Optional GitOrigin-RevId: aba1f4a9f832423626c5e8c64d2777def48df2bc
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f2349bb136
commit
58b3f11a83
+3
-10
@@ -393,21 +393,14 @@ public class MethodCallInstruction extends ExpressionPushingInstruction {
|
||||
DfaValue precalculated = getPrecalculatedReturnValue();
|
||||
PsiType type = getResultType();
|
||||
|
||||
SpecialField field = SpecialField.findSpecialField(myTargetMethod);
|
||||
if (field != null) {
|
||||
return field.createValue(factory, qualifierValue);
|
||||
VariableDescriptor descriptor = JavaDfaValueFactory.getAccessedVariableOrGetter(myTargetMethod);
|
||||
if (descriptor instanceof SpecialField || descriptor != null && qualifierValue instanceof DfaVariableValue) {
|
||||
return descriptor.createValue(factory, qualifierValue);
|
||||
}
|
||||
if (precalculated != null) {
|
||||
return precalculated;
|
||||
}
|
||||
|
||||
if (getContext() instanceof PsiMethodReferenceExpression && qualifierValue instanceof DfaVariableValue) {
|
||||
VariableDescriptor descriptor = JavaDfaValueFactory.getAccessedVariableOrGetter(myTargetMethod);
|
||||
if (descriptor != null) {
|
||||
return descriptor.createValue(factory, qualifierValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (type != null && !(type instanceof PsiPrimitiveType)) {
|
||||
Nullability nullability = myReturnNullability;
|
||||
Mutability mutable = Mutability.UNKNOWN;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class OptionalAsQualifier {
|
||||
|
||||
private static void example(@Nullable Container value) {
|
||||
Optional<Container> optional = Optional.ofNullable(value);
|
||||
if (optional.isPresent() && optional.get().getValue() != null) {
|
||||
foo(optional.get().getValue());
|
||||
}
|
||||
|
||||
if (value != null) {
|
||||
if (value.getValue() != null) {
|
||||
foo(value.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void foo(@NotNull Object val) {}
|
||||
|
||||
private static class Container {
|
||||
@Nullable private final Object val;
|
||||
|
||||
private Container(@Nullable Object val) {
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Object getValue() {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -260,6 +260,7 @@ public class DataFlowInspection8Test extends DataFlowInspectionTestCase {
|
||||
public void testLambdaAfterNullCheck() { doTest(); }
|
||||
public void testFlatMapSideEffect() { doTest(); }
|
||||
public void testOptionalValueTracking() { doTest(); }
|
||||
public void testOptionalAsQualifier() { doTest(); }
|
||||
public void testClearZeroesSize() { doTest(); }
|
||||
public void testLambdaInlineReassignReturnWithDeeperEquality() { doTest(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user