Skip to content

False positive in HSM_HIDING_METHOD for "switch on enums" code #3305

@iloveeclipse

Description

@iloveeclipse

Regression in 4.9.1, via #2467

For the code below compiled with Java 21 eclipse compiler, SpotBugs reports false positive

The method '$SWITCH_TABLE$SwitchTableBug$X()' in class 'B' hides a method in class 'A'

with the HSM_HIDING_METHOD warning.
This is wrong. synthetic SWITCH_TABLE generated by compiler should never be considered as a coding issue.

public class SwitchTableBug {
	class A {
		public void hello() {
			// Switch on local variable
			X x = X.Z;
			switch (x) {
			case Y: {
				System.out.println("Y");
				break;
			}
			default: break;
			}
		}
	}

	class B extends A {
		X x = X.Z;
		@Override
		public void hello() {
			// Switch on a field with same name
			switch (x) {
			case Y: {
				System.out.println("Y");
				break;
			}
			default: break;
			}
		}
	}

	enum X { Y, Z }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions