Skip to content

NPECheck (the “Null Pointer Dereference” hint) should support switches with case null #7949

@ExE-Boss

Description

@ExE-Boss

Apache NetBeans version

Apache NetBeans 23

What happened

When any switch statement or expression has a nullable parameter and case null, it won’t implicitly throw a NullPointerException, so NPECheck shouldn’t report a warning in that case.

Language / Project Type / NetBeans Component

No response

How to reproduce

@interface Nullable {}

enum SomeEnum { FOO, BAR, BAZ }

class Test {
	void testSwitch(@Nullable SomeEnum someEnum) {
		// incorrectly reports null warning on the next line:
		switch (someEnum) {
			case FOO	-> { /* do stuff with FOO	*/ }
			case BAR	-> { /* do stuff with BAR	*/ }
			case BAZ	-> { /* do stuff with BAZ	*/ }
			case null	-> { /* do stuff with null	*/ }
		}
	}
}

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows 11

JDK

OpenJDK Runtime Environment Temurin-23+37 (build 23+37)

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

No response

Are you willing to submit a pull request?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    Java[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)hintskind:bugBug report or fix

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions