Skip to content

Commit

Permalink
Fixed IllegalArgumentException in OpcodeStack.constantToInt
Browse files Browse the repository at this point in the history
This fixes issue #893

Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
  • Loading branch information
iloveeclipse committed Sep 30, 2020
1 parent c0cbb10 commit c28885f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Currently the versioning policy of this project follows [Semantic Versioning v2.
### Changed
* Bump jaxen from 1.1.6 to 1.2.0 supporting Java 11 compilation ([#1316](https://github.com/spotbugs/spotbugs/issues/1316))
* Fixed error dialog on cancelling SpotBugs job in Eclipse ([#1314](https://github.com/spotbugs/spotbugs/issues/1314))
* Fixed IllegalArgumentException in OpcodeStack.constantToInt ([#893](https://github.com/spotbugs/spotbugs/issues/893))
* Bump ASM from 8.0.1 to 9.0 supporting JDK16 (sealed classes)

## 4.1.3 - 2020-09-25
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.umd.cs.findbugs.ba;

import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.Test;

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

public class Issue893Test extends AbstractIntegrationTest {

@Test
public void test() {
performAnalysis("ghIssues/Issue893.class");
BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().build();
assertThat(getBugCollection(), containsExactly(0, bugTypeMatcher));
}

}
4 changes: 4 additions & 0 deletions spotbugs/src/main/java/edu/umd/cs/findbugs/OpcodeStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,10 @@ private int constantToInt(Item it) {
if (constant instanceof Character) {
return ((Character) constant).charValue();
}
if (constant instanceof Boolean) {
Boolean val = (Boolean) constant;
return val.booleanValue() ? 1 : 0;
}
throw new IllegalArgumentException(String.valueOf(constant));
}

Expand Down
10 changes: 10 additions & 0 deletions spotbugsTestCases/src/java/ghIssues/Issue893.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ghIssues;

public class Issue893 {
public boolean test() throws Exception {
Boolean b = Boolean.valueOf(true);
// Line below should not throw IllegalArgumentException during analysis
b &= Boolean.valueOf(false);
return b;
}
}

0 comments on commit c28885f

Please sign in to comment.