Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ExE-Boss opened this issue Nov 9, 2024 · 0 comments · May be fixed by #7980
Open
Labels
hints Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) kind:bug Bug report or fix

Comments

@ExE-Boss
Copy link

ExE-Boss commented Nov 9, 2024

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

@ExE-Boss ExE-Boss added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Nov 9, 2024
@mbien mbien added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) hints labels Nov 10, 2024
@mbien mbien removed the needs:triage Requires attention from one of the committers label Nov 22, 2024
@mbien mbien linked a pull request Nov 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hints Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) kind:bug Bug report or fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants