mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 08:51:02 +07:00
Call pushExpressionResult after field flushing so CommonDataflow (and other clients) has flushed result
Fixes IDEA-230116 Incorrect "Redundant operation on empty container" inspection result GitOrigin-RevId: d764150c114bca699202dc39160efc084c077036
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9e5e9dadef
commit
acd079d592
@@ -233,7 +233,11 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
|||||||
DfaValue defaultResult = runner.getFactory().getObjectType(returnType, DfaPsiUtil.getElementNullability(returnType, method));
|
DfaValue defaultResult = runner.getFactory().getObjectType(returnType, DfaPsiUtil.getElementNullability(returnType, method));
|
||||||
Set<DfaCallState> currentStates = Collections.singleton(new DfaCallState(state.createClosureState(), callArguments));
|
Set<DfaCallState> currentStates = Collections.singleton(new DfaCallState(state.createClosureState(), callArguments));
|
||||||
for (MethodContract contract : contracts) {
|
for (MethodContract contract : contracts) {
|
||||||
currentStates = addContractResults(contract, currentStates, runner.getFactory(), new HashSet<>(), defaultResult, methodRef);
|
Set<DfaMemoryState> results = new HashSet<>();
|
||||||
|
currentStates = addContractResults(contract, currentStates, runner.getFactory(), results, defaultResult, methodRef);
|
||||||
|
for (DfaMemoryState result : results) {
|
||||||
|
pushExpressionResult(result.pop(), new ResultOfInstruction(methodRef), result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (DfaCallState currentState: currentStates) {
|
for (DfaCallState currentState: currentStates) {
|
||||||
pushExpressionResult(defaultResult, new ResultOfInstruction(methodRef), currentState.myMemoryState);
|
pushExpressionResult(defaultResult, new ResultOfInstruction(methodRef), currentState.myMemoryState);
|
||||||
@@ -366,7 +370,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (DfaCallState callState : currentStates) {
|
for (DfaCallState callState : currentStates) {
|
||||||
pushExpressionResult(defaultResult, instruction, callState.myMemoryState);
|
callState.myMemoryState.push(defaultResult);
|
||||||
finalStates.add(callState.myMemoryState);
|
finalStates.add(callState.myMemoryState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,6 +380,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
|||||||
if (instruction.shouldFlushFields()) {
|
if (instruction.shouldFlushFields()) {
|
||||||
state.flushFields();
|
state.flushFields();
|
||||||
}
|
}
|
||||||
|
pushExpressionResult(state.pop(), instruction, state);
|
||||||
result[i++] = new DfaInstructionState(runner.getInstruction(instruction.getIndex() + 1), state);
|
result[i++] = new DfaInstructionState(runner.getInstruction(instruction.getIndex() + 1), state);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -507,7 +512,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
|||||||
}
|
}
|
||||||
if(state != null) {
|
if(state != null) {
|
||||||
DfaValue result = contract.getReturnValue().getDfaValue(factory, defaultResult, new DfaCallState(state, arguments));
|
DfaValue result = contract.getReturnValue().getDfaValue(factory, defaultResult, new DfaCallState(state, arguments));
|
||||||
pushExpressionResult(result, new ResultOfInstruction(expression), state);
|
state.push(result);
|
||||||
finalStates.add(state);
|
finalStates.add(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
class TestInspection
|
||||||
|
{
|
||||||
|
public static Stream<String> foo2(Object o)
|
||||||
|
{
|
||||||
|
HashSet<String> set = new HashSet<>();
|
||||||
|
return collect(o, set).stream();
|
||||||
|
}
|
||||||
|
public static Stream<String> foo(Object o)
|
||||||
|
{
|
||||||
|
return collect(o, new HashSet<>()).stream();
|
||||||
|
}
|
||||||
|
private static Collection<String> collect(Object o, Collection<String> result)
|
||||||
|
{
|
||||||
|
collectAll(o, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
private static void collectAll(Object o, Collection<String> result)
|
||||||
|
{
|
||||||
|
result.add("foo");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,9 @@ public class RedundantOperationOnEmptyContainerInspectionTest extends LightJavaI
|
|||||||
public void testStaticInitializer() {
|
public void testStaticInitializer() {
|
||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
public void testEmptyCollectionReturnThis() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user