From 7de1dff5275eaf954711ab6c6b9f5df577117a01 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Wed, 20 Feb 2019 11:18:37 +0700 Subject: [PATCH] DataFlowInstructionVisitor: allow reporting variable assigned to the same value for Strings --- .../dataFlow/DataFlowInstructionVisitor.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInstructionVisitor.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInstructionVisitor.java index cefd5ae48ed7..b1d4a1afc4e8 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInstructionVisitor.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInstructionVisitor.java @@ -53,9 +53,7 @@ final class DataFlowInstructionVisitor extends StandardInstructionVisitor { @Override public DfaInstructionState[] visitAssign(AssignInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) { PsiExpression left = instruction.getLExpression(); - if (left != null && !Boolean.FALSE.equals(mySameValueAssigned.get(left)) && !TypeUtils.isJavaLangString(left.getType())) { - // Reporting strings is skipped because string reassignment might be intentionally used to deduplicate the heap objects - // (we compare strings by contents) + if (left != null && !Boolean.FALSE.equals(mySameValueAssigned.get(left))) { if (!left.isPhysical()) { if (LOG.isDebugEnabled()) { LOG.debug("Non-physical element in assignment instruction: " + left.getParent().getText(), new Throwable()); @@ -65,6 +63,9 @@ final class DataFlowInstructionVisitor extends StandardInstructionVisitor { DfaValue target = memState.getStackValue(1); if (target != null && memState.areEqual(value, target) && !(value instanceof DfaConstValue && isFloatingZero(((DfaConstValue)value).getValue())) && + // Reporting strings is skipped because string reassignment might be intentionally used to deduplicate the heap objects + // (we compare strings by contents) + !(TypeUtils.isJavaLangString(left.getType()) && !memState.isNull(value)) && !isAssignmentToDefaultValueInConstructor(instruction, runner, target)) { mySameValueAssigned.merge(left, Boolean.TRUE, Boolean::logicalAnd); }