Skip to content

Commit

Permalink
Check for LOOKUPSWITCH or TABLESWITCH instructions (#2979)
Browse files Browse the repository at this point in the history
* fix: check for LOOKUPSWITCH or TABLESWITCH instructions

When looking for a switch the instruction might be LOOKUPSWITCH or
TABLESWITCH. Look for Select which is the base class for both.
See #2782
See #2937

* fix: moved the change log to Unreleased
  • Loading branch information
gtoison committed May 10, 2024
1 parent d1d7ac0 commit e8e3c10
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,8 @@ This is the changelog for SpotBugs. This follows [Keep a Changelog v1.0.0](http:
Currently the versioning policy of this project follows [Semantic Versioning v2.0.0](http://semver.org/spec/v2.0.0.html).

## Unreleased - 2024-??-??
### Fixed
- Do not report BC_UNCONFIRMED_CAST for Java 21's type switches when the switch instruction is TABLESWITCH ([#2782](https://github.com/spotbugs/spotbugs/issues/2782))

## 4.8.5 - 2024-05-03
### Fixed
Expand Down
Expand Up @@ -25,7 +25,7 @@
import org.apache.bcel.generic.LDC;
import org.apache.bcel.generic.MethodGen;
import org.apache.bcel.generic.ReferenceType;
import org.apache.bcel.generic.LOOKUPSWITCH;
import org.apache.bcel.generic.Select;
import org.apache.bcel.generic.Type;
import org.apache.bcel.generic.TypedInstruction;

Expand Down Expand Up @@ -211,8 +211,8 @@ private void analyzeMethod(ClassContext classContext, Method method) throws CFGB
boolean wasMethodInvocationWasGeneric = methodInvocationWasGeneric;
methodInvocationWasGeneric = false;

if (ins instanceof LOOKUPSWITCH) {
LOOKUPSWITCH switchInstruction = (LOOKUPSWITCH) ins;
if (ins instanceof Select) {
Select switchInstruction = (Select) ins;
int[] indices = switchInstruction.getIndices();

switchHandler.enterSwitch(ins.getOpcode(),
Expand Down

0 comments on commit e8e3c10

Please sign in to comment.