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

Replace if chain with switch can throw NPEs #8266

Open
mbien opened this issue Feb 21, 2025 · 0 comments
Open

Replace if chain with switch can throw NPEs #8266

mbien opened this issue Feb 21, 2025 · 0 comments
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

@mbien
Copy link
Member

mbien commented Feb 21, 2025

Apache NetBeans version

Apache NetBeans 24

What happened

simplified snippet taken from NB repo:

    private void checkProgress(ExecutionEventObject eeo) {
        if (ExecutionEvent.Type.ProjectDiscoveryStarted.equals(eeo.type)) {
        } else if (ExecutionEvent.Type.SessionStarted.equals(eeo.type)) {
        } else if (ExecutionEvent.Type.ProjectStarted.equals(eeo.type)) {
        }
    }

run hint -> convert to switch statement

results:

java.lang.NullPointerException: Cannot invoke "org.netbeans.spi.java.hints.HintContext.getInfo()" because "this.ctx" is null
	at org.netbeans.modules.java.hints.bugs.NPECheck$VisitorImpl.visitPrimitiveWrapperMethods(NPECheck.java:1076)
	at org.netbeans.modules.java.hints.bugs.NPECheck$VisitorImpl.visitMethodInvocation(NPECheck.java:1042)
	at org.netbeans.modules.java.hints.bugs.NPECheck$VisitorImpl.visitMethodInvocation(NPECheck.java:575)
	at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1877)
	at com.sun.source.util.TreeScanner.scan(TreeScanner.java:91)
	at org.netbeans.api.java.source.support.CancellableTreeScanner.scan(CancellableTreeScanner.java:69)
	at org.netbeans.modules.java.hints.bugs.NPECheck$VisitorImpl.scan(NPECheck.java:677)
	at org.netbeans.modules.java.hints.bugs.NPECheck$VisitorImpl.visitBinary(NPECheck.java:898)
	at org.netbeans.modules.java.hints.bugs.NPECheck$VisitorImpl.visitBinary(NPECheck.java:575)
	at com.sun.tools.javac.tree.JCTree$JCBinary.accept(JCTree.java:2231)
	at com.sun.source.util.TreeScanner.scan(TreeScanner.java:91)
	at org.netbeans.api.java.source.support.CancellableTreeScanner.scan(CancellableTreeScanner.java:69)
	at org.netbeans.modules.java.hints.bugs.NPECheck$VisitorImpl.scan(NPECheck.java:677)
	at org.netbeans.modules.java.hints.bugs.NPECheck$VisitorImpl.visitNewClass(NPECheck.java:1008)

null seems to be a legal value for ctx - judging from the null checks in other places of the class.

Language / Project Type / NetBeans Component

No response

How to reproduce

see above

Did this work correctly in an earlier version?

No / Don't know

Operating System

linux

JDK

23

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

No response

Are you willing to submit a pull request?

No - not right now

@mbien mbien added hints Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) kind:bug Bug report or fix labels Feb 21, 2025
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

No branches or pull requests

1 participant