Skip to content

NullPointer while open jsp File #9398

@AlfaSack

Description

@AlfaSack

Apache NetBeans version

Apache NetBeans 29

What happened

Apache NetBeans version

Apache NetBeans 29

What happened

Opening any .jsp file via the Projects window causes the editor tab to flash open and immediately close. The IDE log shows a NullPointerException in JspParserImpl.createParseProxy(JspParserImpl.java:234):

java.lang.NullPointerException: Cannot invoke "org.netbeans.api.j2ee.core.Profile.isAtLeast(org.netbeans.api.j2ee.core.Profile)" because the return value of "org.netbeans.modules.web.api.webmodule.WebModule.getJ2eeProfile()" is null
    at org.netbeans.modules.web.jspparser.JspParserImpl.createParseProxy(JspParserImpl.java:234)
    at org.netbeans.modules.web.jspparser.JspParserImpl.getParseProxy(JspParserImpl.java:225)
    at org.netbeans.modules.web.jspparser.JspParserImpl.getJspOpenInfo(JspParserImpl.java:177)
    at org.netbeans.modules.web.core.jsploader.TagLibParseSupport.getCachedOpenInfo(TagLibParseSupport.java:246)
    at org.netbeans.modules.web.core.jsploader.JspDataObject.findFileEncoding(JspDataObject.java:287)
    at org.netbeans.modules.web.core.jsploader.JspDataObject.getFileEncoding(JspDataObject.java:276)
    at org.netbeans.modules.web.core.jsploader.BaseJspEditorSupport.verifyEncoding(BaseJspEditorSupport.java:276)
    at org.netbeans.modules.web.core.jsploader.BaseJspEditorSupport.open(BaseJspEditorSupport.java:257)
    at org.openide.actions.OpenAction.performAction(OpenAction.java:59)
    ...

A follow-up IllegalStateException is then logged from BaseJspEditorSupport$4.propertyChange during the resulting document-close cleanup, which is why the tab disappears instantly:

INFO [org.netbeans.modules.web.core.jsploader.BaseJspEditorSupport$4]: property change fired with both new and old value null!
java.lang.IllegalStateException
    at org.netbeans.modules.web.core.jsploader.BaseJspEditorSupport$4.propertyChange(BaseJspEditorSupport.java:166)
    ...
    at org.openide.text.DocumentOpenClose$DocumentClose.run(DocumentOpenClose.java:985)

Root cause appears to be that JspParserImpl.createParseProxy calls webModule.getJ2eeProfile().isAtLeast(...) without guarding against getJ2eeProfile() returning null. WebModule.getJ2eeProfile() legitimately returns null for projects that aren't registered as Jakarta EE web modules — free-form projects, Ant Java projects that happen to contain .jsp files, GWT projects with a webapp/ directory, or .jsp files opened standalone from the Favorites window.

This is a regression introduced by #8976 (Enable parsing of JSP 3.0 (Jakarta) based sources) in NetBeans 29.

Language / Project Type / NetBeans Component

JSP / enterprise/web.jspparser

How to reproduce

  1. Have any project containing .jsp files where WebModule.getJ2eeProfile() returns null (e.g. Ant free-form project, or a Java/GWT project with .jsp files under a webapp folder but no Jakarta EE profile configured).
  2. Double-click a .jsp file in the Projects window.
  3. The editor tab opens and immediately closes; the NPE above appears in messages.log.

Did this work correctly in an earlier version?

Yes — works correctly in Apache NetBeans 28.

Operating System

Linux — Ubuntu MATE 24.04 (kernel 6.x, amd64)

JDK

Apache NetBeans packaging

Anything else

Likely fix: null-guard the WebModule.getJ2eeProfile() call in JspParserImpl.createParseProxy (and getParseProxy), falling back to the JSP 2.x parsing path when no profile is set. As a current workaround, disabling the org.netbeans.modules.web.jspparser module (Tools → Plugins → Installed) lets .jsp files open again, but obviously without JSP parsing/completion.

cc @matthiasblaesing — author of #8976.

Are you willing to submit a pull request?

Language / Project Type / NetBeans Component

No response

How to reproduce

Simply open .jsp file with active "Java Web and EE".

Did this work correctly in an earlier version?

Apache NetBeans 28

Operating System

Ubuntu

JDK

JDBK 25

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

No response

Are you willing to submit a pull request?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:bugBug report or fixneeds:triageRequires attention from one of the committers

    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