Skip to content

[false-positive]SF_SWITCH_NO_DEFAULT detect false positive result: some switchs with default are detected. #1148

@wuchiuwong

Description

@wuchiuwong

Affects SpotBugs Version:
spotbugs-4.0.0-RC2

Rule:
SF_SWITCH_NO_DEFAULT

Description:
Detect false positive result: some switchs with default are detected.
This rule is implemented in SpotBugs.jar\main\java\edu\umd\cs\findbugs\detect\SwitchFallthrough.java.
The rule uses a complex method based on bytecode transfer to detect switch without default, and there are special cases where this method is not applicable.

Code Sample demonstrating the issue:

example 1:
@Override
protected int updateData(QTBlockData targetBlockData, QuitType targetData, QuitType sourceData, int indexInTarget) {
	FanoutWithLocation fwl = targetBlockData.getFanout(indexInTarget);
	FanoutType ft = fwl.getType();
	EntryId id = fwl.getEntryId();
	int result = 0;
	switch (ft) {	//this line is marked
	case DO:
	case EXTRINSIC:
		CallType ct = targetData.getFanout(id);
		return ct.updateFromFanout(sourceData);
	case GOTO:
	case ASSUMED_GOTO:
		result = targetData.markQuitFromGoto(sourceData, fwl.getCodeLocation());
	default:
		result += targetData.updateCallTypes(sourceData);
	}
	return result;
}		

example 2:
public void setDamageParam(int i, double v){
	switch(i){	//this line is marked
		case 0:  TACKLE = v;
		case 1:  PUNCH = v;
		case 2:  KICK = v;
		case 3:  HEADBUTT = v;
		case 4:  MAGIC = v;
		default:
			break;
	}
}

example 3:
public void addData(UsageType _type, ArrayList<Integer> _list)
{
	switch (_type)	//this line is marked
	{
	case CPU:
		this.cpuData.addAll(_list);

	case DISK:
		this.diskData.addAll(_list);

	case MEMORY:
		this.memData.addAll(_list);

	default:
		break;
	}
}

Expected outcome:
false-positive

Running SpotBugs through:
command line

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions