[java-inspections] UseHashCodeMethodInspection: check for side-effects (IDEA-338114)

GitOrigin-RevId: cf54ae1e7c99e0ddff88bf8a6bf951b36f8b89b7
This commit is contained in:
Tagir Valeev
2024-01-15 13:03:37 +01:00
committed by intellij-monorepo-bot
parent 96cc92c0ce
commit 3fad9d4a33
2 changed files with 10 additions and 2 deletions

View File

@@ -90,8 +90,8 @@ public final class UseHashCodeMethodInspection extends AbstractBaseJavaLocalInsp
if (shiftingExpression.getOperationSign().getTokenType() != JavaTokenType.GTGTGT) return false;
PsiExpression leftSubOperand = shiftingExpression.getLOperand();
return EquivalenceChecker.getCanonicalPsiEquivalence()
.expressionsAreEquivalent(leftOperand, leftSubOperand) &&
return EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(leftOperand, leftSubOperand) &&
!SideEffectChecker.mayHaveSideEffects(leftOperand) &&
Objects.equals(32, ExpressionUtils.computeConstantExpression(shiftingExpression.getROperand()));
}

View File

@@ -0,0 +1,8 @@
// "Replace with 'Long.hashCode()'" "false"
public class Test {
long var = 1234567890123456789L;
public void testMethod() {
int result = (int<caret>)((var++) ^ ((var++) >>> /*shift amount*/ 32));
}
}