mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-158970 (Bug in Java pointless bitwise expression inspection)
This commit is contained in:
+4
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2014 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2016 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,6 +30,7 @@ import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.PsiReplacementUtil;
|
||||
import com.siyeh.ig.psiutils.EquivalenceChecker;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import com.siyeh.ig.psiutils.SideEffectChecker;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -241,8 +242,8 @@ public class PointlessBitwiseExpressionInspection extends BaseInspection {
|
||||
private boolean booleanExpressionIsPointless(PsiExpression[] operands) {
|
||||
PsiExpression previousExpression = null;
|
||||
for (PsiExpression operand : operands) {
|
||||
if (isZero(operand) || isAllOnes(operand) || EquivalenceChecker.getCanonicalPsiEquivalence()
|
||||
.expressionsAreEquivalent(previousExpression, operand)) {
|
||||
if (isZero(operand) || isAllOnes(operand) || (EquivalenceChecker.getCanonicalPsiEquivalence()
|
||||
.expressionsAreEquivalent(previousExpression, operand) && !SideEffectChecker.mayHaveSideEffects(operand))) {
|
||||
return true;
|
||||
}
|
||||
previousExpression = operand;
|
||||
|
||||
+7
@@ -1,5 +1,7 @@
|
||||
package com.siyeh.igtest.bitwise.pointless_bitwise_expression;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class PointlessBitwiseExpression {
|
||||
private static final int ZERO = 0;
|
||||
|
||||
@@ -60,6 +62,11 @@ public class PointlessBitwiseExpression {
|
||||
System.out.println(k);
|
||||
}
|
||||
|
||||
public static void main5(String[] args) {
|
||||
Random in = new Random();
|
||||
System.out.println(in.nextInt() & in.nextInt());
|
||||
}
|
||||
|
||||
void longExpressions(int i, int j) {
|
||||
i = <warning descr="'j & 0 & 100' can be replaced with '0'">j & 0 & 100</warning>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user