Skip to content

Commit

Permalink
fix issue 1472 (#1478)
Browse files Browse the repository at this point in the history
  • Loading branch information
gloNelson committed Apr 8, 2021
1 parent ff6582e commit 9801465
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Currently the versioning policy of this project follows [Semantic Versioning v2.
- Inconsistency in the description of `DLS_DEAD_LOCAL_INCREMENT_IN_RETURN`, `VO_VOLATILE_INCREMENT` and `QF_QUESTIONABLE_FOR_LOOP` ([#1470](https://github.com/spotbugs/spotbugs/issues/1470))
- Should issue warning for SecureRandom object created and used only once ([#1464](https://github.com/spotbugs/spotbugs/issues/1464))
- False positive OBL_UNSATIFIED_OBLIGATION with try with resources ([#79](https://github.com/spotbugs/spotbugs/issues/79))
- `SA_LOCAL_SELF_COMPUTATION` bug ([#1472](https://github.com/spotbugs/spotbugs/issues/1472))

## 4.2.2 - 2021-03-03

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package edu.umd.cs.findbugs.detect;

import edu.umd.cs.findbugs.AbstractIntegrationTest;
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher;
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder;
import org.junit.Test;

import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly;
import static org.junit.Assert.assertThat;


/**
* @see <a href="https://github.com/spotbugs/spotbugs/issues/1472">GitHub issue #1472</a>
*/
public class Issue1472Test extends AbstractIntegrationTest {
@Test
public void test() {
performAnalysis("ghIssues/Issue1472.class");
BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder()
.bugType("SA_LOCAL_SELF_COMPUTATION")
.build();
assertThat(getBugCollection(), containsExactly(4, bugTypeMatcher));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private void checkForSelfOperation(int opCode, String op) {
bugAccumulator.accumulateBug(bug, this);
}

else if (opCode == Const.IXOR && item0.sameValue(item1)) {
else if (item0.sameValue(item1)) {
LocalVariableAnnotation localVariableAnnotation = LocalVariableAnnotation.getLocalVariableAnnotation(this, item0);
if (localVariableAnnotation != null) {
bugAccumulator.accumulateBug(
Expand Down
23 changes: 23 additions & 0 deletions spotbugsTestCases/src/java/ghIssues/Issue1472.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ghIssues;

public class Issue1472 {
int testSA_LOCAL_SELF_COMPUTATION(){
int flags = 1;
return flags ^ flags; // expeected SA_LOCAL_SELF_COMPUTATION
}

int testSA_LOCAL_SELF_COMPUTATION1(){
int flags = 1;
return flags & flags; // expeected SA_LOCAL_SELF_COMPUTATION
}

int testSA_LOCAL_SELF_COMPUTATION2(){
int flags = 1;
return flags - flags; // expeected SA_LOCAL_SELF_COMPUTATION
}

int testSA_LOCAL_SELF_COMPUTATION3(){
int flags = 1;
return flags | flags; // expeected SA_LOCAL_SELF_COMPUTATION
}
}

0 comments on commit 9801465

Please sign in to comment.