Skip to content

False positive warning on switch statements with case null #930

@msridhar

Description

@msridhar

Example:

static Object handleNullableEnumCaseNullDefaultStatement(@Nullable NullableEnum nullableEnum) {
   Object result;
   switch (nullableEnum) {
     case null -> result = new Object();
     default -> result = nullableEnum.toString();
   };
   return result;
}

NullAway warns of a possible null dereference for the switch, but it should not, as there is a case null. (We currently don't warn on switch expressions as we don't match them yet due to google/error-prone#4119, but similar logic is required there.)

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