LSP/TypeScript: NPE when trying to generate getter
See original GitHub issueApache NetBeans version
Apache NetBeans 14 RC 1
What happened
When I try to generate a getter for a class field (and, optionally, also a setter), NetBeans shows the following error in the Notifications window:
Cannot invoke "org.eclipse.lsp4j.WorkspaceEdit.getDocumentChanges()" because "edit" is null
This is the stack trace:
java.lang.NullPointerException: Cannot invoke "org.eclipse.lsp4j.WorkspaceEdit.getDocumentChanges()" because "edit" is null
at org.netbeans.modules.lsp.client.Utils.applyWorkspaceEdit(Utils.java:94)
at org.netbeans.modules.lsp.client.Utils.applyCodeAction(Utils.java:198)
at org.netbeans.modules.lsp.client.bindings.LanguageClientImpl$DiagnosticFixList$CommandBasedFix.implement(LanguageClientImpl.java:299)
[catch] at org.netbeans.modules.editor.hints.HintsUI$1.run(HintsUI.java:810)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)
at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)
How to reproduce
Suppose that I’ve the following TypeScript source file:
export class Student {
private age: number;
}
When I open it in NetBeans, the editor shows a compilation error saying this: ‘age’ is declared but its value is never read. Then, if I do one of these things:
- Option A
- Main menu
- Source
- Fix code…
- Generate ‘get’ and ‘set’ accessors
- Option B
- Click on bulb in editor’s gutter
- Generate ‘get’ and ‘set’ accessors
The error mentioned in the previous section is thrown.
Did this work correctly in an earlier version?
No
Operating System
Debian GNU/Linux 11.3 (Bullseye)
JDK
OpenJDK Runtime Environment (build 17.0.2+8-Debian-1deb11u1)
Apache NetBeans packaging
Apache NetBeans binary zip
Anything else
In NetBeans IDE 13, the same error was thrown when adding an import
automatically, by choosing Add import from <package> in the bulb’s menu. However, in version 14 RC 1 this seems to be fixed.
In NetBeans IDE 14 RC1, this error also occurs when you select a piece of code and try to extract it into a method (or other kind of refactoring). In this case, we need to choose Insert code… instead of Fix code…, but the result is the same.
Are you willing to submit a pull request?
No
Code of Conduct
Yes
Issue Analytics
- State:
- Created a year ago
- Comments:9 (6 by maintainers)
Ok - I pushed a PR, that holds a partial fix: https://github.com/apache/netbeans/pull/4049
Here is a development build from that branch:
https://doppel-helix.eu/NetBeans-dev-dev-de5beb43947a575c5c77eafca7945dda59dff8d0-release.zip
It does not handle the “_typescript.rename” request, but it turns the exception into a log entry with payload, which makes this a usable case in my eyes. In the long run we most probably need to enable language specific plugins to handle these cases, but that is a problem not to be fixed directly before a release.
Thank you - the fix for the exception is trivial - but the it becomes more interesting:
But then it becomes more interesting: the typescript server sends a request to the IDE
_typescript.rename
. The IDE logs that as unsupported and the typescript server then sends an error notification, that the IDE does not support the request. This needs more work and maybe tie in from the typescript plugin in NetBeans itself.