Menu

#1392 Default Case is Missing With Alias Enum Constants

3.0.2
closed-fixed
None
7
2015-10-08
2015-06-30
Clint Shank
No

A public static final EnumType field in an enumeration confuses FindBugs and FindBugs will report a SF_SWITCH_NO_DEFAULT issue when all cases are covered in a switch statement.

For instance, given the following enumeration:

:::java
public enum TrafficLight {
    RED, YELLOW, GREEN;

    // introducing a public static final <EnumType> field introduces
    // a SF_SWITCH_NO_DEFAULT bug
    public static final TrafficLight GO = GREEN;
}

FindBugs will report that a default case is missing even though all enum constants are covered:

:::java
public void showBug(TrafficLight light) {
    // default case is missing, but all cases are covered
    switch (light) {
        case RED:
            System.out.println("red");
            break;
        case YELLOW:
            System.out.println("yellow");
            break;
        case GREEN:
            System.out.println("green");
            break;
    }
}

Discussion

  • Tagir Valeev

    Tagir Valeev - 2015-10-08
    • status: open --> closed-fixed
    • assigned_to: Tagir Valeev
    • Group: 3.x --> 3.0.2
     

Log in to post a comment.

MongoDB Logo MongoDB