fb-contrib icon indicating copy to clipboard operation
fb-contrib copied to clipboard

SF_SWITCH_NO_DEFAULT is not detected if value is returned within switch

Open fenuks opened this issue 4 years ago • 0 comments

I'm using spotbugs maven plugin in version 4.0.0, spotbugs 4.0.3, sb-contrib version 7.4.7, OpenJDK 11.

Example below:

public class Test {

  public static Integer errorNotFound(Example example) {
    // SF_SWITCH_NO_DEFAULT not triggered
    switch (example) {
      case A:
        return 1;
      case B:
        return 2;
    }
    return 3;
  }

  public static Integer errorFound(Example example) {
    // SF_SWITCH_NO_DEFAULT triggered
    Integer result = null;
    switch (example) {
      case A:
        result = 1;
        break;
      case B:
        result = 2;
        break;
    }
    return result;
  }

  private enum Example {
    A, B, C;
  }
}

fenuks avatar Jun 05 '20 13:06 fenuks