netbeans
netbeans copied to clipboard
Fix invalid element references during completion resolution using ElementHandle which has additional text edits
Fixes crashes and incorrect behavior when resolving completion items across different javac contexts.
When completion items are created, they capture Element references from the initial javac context. Later, when the LSP client calls completionItem/resolve to fetch additionalTextEdits, a new javac context may be used (especially if the file was modified). The old Element instances are invalid in the new context, causing Assertion Error rootPackage missing!; currModule: java.base.
So, store ElementHandles instead of stale Elements when creating completion items.
Thanks @lahodaj for helping out.