From 098214398ac3a079a9205a60f6cd1184e2225d2d Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Fri, 19 Apr 2024 15:17:10 +0200 Subject: [PATCH] [java-property-tests] SourceToSinkPropertyInspectionTest fixed Likely, the improvements in inspection were not reflected in test: 1. Later assignment to local variable overwrites the previous tainted state 2. Constant conditions like (1 == 1) are evaluated by inspection, so we need a non-constant one in test GitOrigin-RevId: 62e373f85011b8302186cdf3b951cb8b056a7603 --- .../SourceToSinkPropertyInspectionTest.java | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/jvm/jvm-analysis-java-tests/testSrc/com/intellij/java/propertyBased/SourceToSinkPropertyInspectionTest.java b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/java/propertyBased/SourceToSinkPropertyInspectionTest.java index 0123ceaa1eff..28d1e8665cb8 100644 --- a/jvm/jvm-analysis-java-tests/testSrc/com/intellij/java/propertyBased/SourceToSinkPropertyInspectionTest.java +++ b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/java/propertyBased/SourceToSinkPropertyInspectionTest.java @@ -14,6 +14,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase; +import com.intellij.util.containers.ContainerUtil; import org.intellij.lang.annotations.Language; import org.jetbrains.annotations.NotNull; import org.jetbrains.jetCheck.Generator; @@ -271,7 +272,7 @@ public class SourceToSinkPropertyInspectionTest extends LightJavaCodeInsightFixt @Override public @NotNull String getText() { - return String.format("((1 == 1) ? %s : %s)", myLhs.getText(), myRhs.getText()); + return String.format("((Math.random() > 0.5) ? %s : %s)", myLhs.getText(), myRhs.getText()); } @Override @@ -355,16 +356,8 @@ public class SourceToSinkPropertyInspectionTest extends LightJavaCodeInsightFixt @Override public @NotNull TaintState taintState() { - TaintState taintState = TaintState.SAFE; - for (Variable variable : myVariables) { - if (variable.isField()) { - taintState = TaintState.UNKNOWN; - } - else { - taintState = taintState.join(variable.taintState()); - } - } - return taintState; + return ContainerUtil.exists(myVariables, Variable::isField) ? TaintState.UNKNOWN : + myVariables.stream().findFirst().map(Variable::taintState).orElse(TaintState.SAFE); } private static @NotNull MethodBody generate(@NotNull ImperativeCommand.Environment env) { @@ -392,14 +385,7 @@ public class SourceToSinkPropertyInspectionTest extends LightJavaCodeInsightFixt @Override public @NotNull TaintState taintState() { if (isField()) return TaintState.UNKNOWN; - TaintState taintState = myDeclaration.taintState(); - if (taintState == TaintState.TAINTED) return taintState; - for (Assignment assignment : myAssignments) { - TaintState assignmentState = assignment.taintState(); - if (assignmentState == TaintState.TAINTED) return assignmentState; - if (taintState == TaintState.SAFE) taintState = assignmentState; - } - return taintState; + return myAssignments.stream().reduce((a, b) -> b).map(Assignment::taintState).orElse(myDeclaration.taintState()); } public boolean isField() {