Skip to content

NPE thrown when server returns a TextDocumentSyncOptions.save to null #1076

Closed

Description

@rcjsuen

IDE: GoLand 2025.1 (Build #GO-251.23774.430, built on April 14, 2025)
Version: 0.13.1-20250529-113057

  1. Have the Docker Language Server configured and setup for compose.yaml files.
  2. Restart with no files opened.
  3. Create a compose.yaml file.
  4. Type some stuff and try to save immediately.
  5. Error is thrown.

Image

2025-05-30-lsp4ij-save-bug.mov
java.lang.NullPointerException: Cannot invoke "org.eclipse.lsp4j.jsonrpc.messages.Either.isLeft()" because "saveOptions" is null
	at com.redhat.devtools.lsp4ij.DocumentContentSynchronizer.documentSaved(DocumentContentSynchronizer.java:229)
	at com.redhat.devtools.lsp4ij.LSPFileListener.contentsChanged(LSPFileListener.java:113)
	at com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter.fireAfter(BulkVirtualFileListenerAdapter.java:47)
	at com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter.after(BulkVirtualFileListenerAdapter.java:38)
	at com.intellij.util.messages.impl.MessageBusImplKt.invokeMethod(MessageBusImpl.kt:768)
	at com.intellij.util.messages.impl.MessageBusImplKt.invokeListener(MessageBusImpl.kt:708)
	at com.intellij.util.messages.impl.MessageBusImplKt.executeOrAddToQueue(MessageBusImpl.kt:533)
	at com.intellij.util.messages.impl.ToDirectChildrenMessagePublisher.publish$intellij_platform_core(CompositeMessageBus.kt:281)
	at com.intellij.util.messages.impl.MessagePublisher.invoke(MessageBusImpl.kt:481)
	at jdk.proxy2/jdk.proxy2.$Proxy179.after(Unknown Source)
	at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.lambda$fireAfterEvents$26(PersistentFSImpl.java:1518)
	at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.runSuppressing(PersistentFSImpl.java:1148)
	at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl.fireAfterEvents(PersistentFSImpl.java:1515)
	at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl$3.writeToDisk(PersistentFSImpl.java:1067)
	at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl$3.close(PersistentFSImpl.java:1050)
	at com.intellij.openapi.fileEditor.impl.LoadTextUtil.write(LoadTextUtil.java:430)
	at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.lambda$doSaveDocumentInWriteAction$3(FileDocumentManagerImpl.java:445)
	at com.intellij.pom.core.impl.PomModelImpl.guardPsiModificationsIn(PomModelImpl.java:332)
	at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.doSaveDocumentInWriteAction(FileDocumentManagerImpl.java:433)
	at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.lambda$doSaveDocument$2(FileDocumentManagerImpl.java:386)
	at com.intellij.openapi.application.WriteAction.lambda$run$1(WriteAction.java:85)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction$lambda$15(AnyThreadWriteThreadingSupport.kt:623)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWithTemporaryThreadLocal(AnyThreadWriteThreadingSupport.kt:204)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction(AnyThreadWriteThreadingSupport.kt:623)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction(AnyThreadWriteThreadingSupport.kt:617)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:998)
	at com.intellij.openapi.application.WriteAction.run(WriteAction.java:84)
	at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.doSaveDocument(FileDocumentManagerImpl.java:386)
	at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveDocuments(FileDocumentManagerImpl.java:303)
	at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:278)
	at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:271)
	at com.intellij.ide.actions.SaveAllAction.actionPerformed(SaveAllAction.kt:25)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.doPerformActionOrShowPopup(ActionUtil.kt:383)
	at com.intellij.openapi.keymap.impl.ActionProcessor.performAction(ActionProcessor.java:32)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$actionProcessor$1.performAction(IdeKeyEventDispatcher.kt:498)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.doPerformActionInner$lambda$8$lambda$7(IdeKeyEventDispatcher.kt:846)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:109)
	at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:98)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.doPerformActionInner$lambda$8(IdeKeyEventDispatcher.kt:846)
	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.performWithActionCallbacks(ActionManagerImpl.kt:1167)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks(ActionUtil.kt:405)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.doPerformActionInner(IdeKeyEventDispatcher.kt:844)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.access$doPerformActionInner(IdeKeyEventDispatcher.kt:1)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.kt:576)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.kt:511)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.kt:450)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.kt:443)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.kt:305)
	at com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.kt:515)
	at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$17(IdeEventQueue.kt:474)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteIntentReadAction$lambda$6(AnyThreadWriteThreadingSupport.kt:274)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWithTemporaryThreadLocal(AnyThreadWriteThreadingSupport.kt:204)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteIntentReadAction(AnyThreadWriteThreadingSupport.kt:274)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runPreventiveWriteIntentReadAction(AnyThreadWriteThreadingSupport.kt:218)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:474)
	at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$12$lambda$11$lambda$10$lambda$9(IdeEventQueue.kt:307)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:864)
	at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$12$lambda$11$lambda$10(IdeEventQueue.kt:306)
	at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$3(IdeEventQueue.kt:958)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:117)
	at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:958)
	at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$12(IdeEventQueue.kt:301)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:341)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

Activity

  1. added
    bug
    on May 30, 2025
  2. angelozerr commented on May 30, 2025

    @angelozerr
    Contributor

    You will have this problem every time since now I use capability to know if didSave must be done.

    You language server returns:

    Result: {
      "capabilities": {
        "textDocumentSync": {
          "openClose": true,
          "change": 1
        }
    

    with a save, I need to take care of that, but I don't know if it means that you don't support save.

  3. rcjsuen commented on May 30, 2025

    @rcjsuen
    ContributorAuthor

    According to the 3.17 specification, I do not think I am doing anything wrong. I have returned a valid TextDocumentSyncOptions object. 🤔

    interface ServerCapabilities {
    
    	/**
    	 * The position encoding the server picked from the encodings offered
    	 * by the client via the client capability `general.positionEncodings`.
    	 *
    	 * If the client didn't provide any position encodings the only valid
    	 * value that a server can return is 'utf-16'.
    	 *
    	 * If omitted it defaults to 'utf-16'.
    	 *
    	 * @since 3.17.0
    	 */
    	positionEncoding?: PositionEncodingKind;
    
    	/**
    	 * Defines how text documents are synced. Is either a detailed structure
    	 * defining each notification or for backwards compatibility the
    	 * TextDocumentSyncKind number. If omitted it defaults to
    	 * `TextDocumentSyncKind.None`.
    	 */
    	textDocumentSync?: TextDocumentSyncOptions | TextDocumentSyncKind;
    export interface TextDocumentSyncOptions {
    	/**
    	 * Open and close notifications are sent to the server. If omitted open
    	 * close notifications should not be sent.
    	 */
    	openClose?: boolean;
    
    	/**
    	 * Change notifications are sent to the server. See
    	 * TextDocumentSyncKind.None, TextDocumentSyncKind.Full and
    	 * TextDocumentSyncKind.Incremental. If omitted it defaults to
    	 * TextDocumentSyncKind.None.
    	 */
    	change?: TextDocumentSyncKind;
    }
  4. rcjsuen commented on May 30, 2025

    @rcjsuen
    ContributorAuthor

    Oh, I see now. Interesting, if you search for TextDocumentSyncOptions { in the specification I see two hits. And the other one has more content.

    I don't know if it means that you don't support save.

    I think it's assumed that the value is false if it is save? is not there.

    export interface [TextDocumentSyncOptions](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentSyncOptions) {
    	/**
    	 * Open and close notifications are sent to the server. If omitted open
    	 * close notification should not be sent.
    	 */
    	openClose?: boolean;
    	/**
    	 * Change notifications are sent to the server. See
    	 * TextDocumentSyncKind.None, TextDocumentSyncKind.Full and
    	 * TextDocumentSyncKind.Incremental. If omitted it defaults to
    	 * TextDocumentSyncKind.None.
    	 */
    	change?: [TextDocumentSyncKind](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentSyncKind);
    	/**
    	 * If present will save notifications are sent to the server. If omitted
    	 * the notification should not be sent.
    	 */
    	willSave?: boolean;
    	/**
    	 * If present will save wait until requests are sent to the server. If
    	 * omitted the request should not be sent.
    	 */
    	willSaveWaitUntil?: boolean;
    	/**
    	 * If present save notifications are sent to the server. If omitted the
    	 * notification should not be sent.
    	 */
    	save?: boolean | [SaveOptions](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#saveOptions);
    }
  5. angelozerr commented on May 30, 2025

    @angelozerr
    Contributor

    Oh, I see now. Interesting, if you search for TextDocumentSyncOptions { in the specification I see two hits. And the other one has more content.

    I don't know if it means that you don't support save.

    I think it's assumed that the value is false if it is save? is not there.

    export interface TextDocumentSyncOptions {
    /**

    • Open and close notifications are sent to the server. If omitted open
    • close notification should not be sent.
      /
      openClose?: boolean;
      /
      *
    • Change notifications are sent to the server. See
    • TextDocumentSyncKind.None, TextDocumentSyncKind.Full and
    • TextDocumentSyncKind.Incremental. If omitted it defaults to
    • TextDocumentSyncKind.None.
      /
      change?: TextDocumentSyncKind;
      /
      *
    • If present will save notifications are sent to the server. If omitted
    • the notification should not be sent.
      /
      willSave?: boolean;
      /
      *
    • If present will save wait until requests are sent to the server. If
    • omitted the request should not be sent.
      /
      willSaveWaitUntil?: boolean;
      /
      *
    • If present save notifications are sent to the server. If omitted the
    • notification should not be sent.
      */
      save?: boolean | SaveOptions;
      }

    Not sure with that because if you define only TextDocumentSynchKind, save is enabled.

  6. changed the title [-]NPE thrown when saving too early[/-] [+]NPE thrown when server returns a TextDocumentSyncOptions.save to null[/+] on May 30, 2025
  7. added a commit that references this issue on May 30, 2025
    d17cd27
  8. angelozerr commented on May 30, 2025

    @angelozerr
    Contributor

    @rcjsuen please see PR #1078 and review it. I enabled the save if not present but I don't know if it is correct. Could you try with vscode and tell me of it send didSave when you save a file

  9. self-assigned this
    on May 30, 2025
  10. added this to the 0.14.0 milestone on May 30, 2025
  11. angelozerr commented on May 30, 2025

    @angelozerr
    Contributor

    @rcjsuen I enable the save by default (if not present), if you see that vscode have different behavior please create an issue and I will fix it.

    I decided to merge the PR to avoid having NPE.

  12. rcjsuen commented on May 30, 2025

    @rcjsuen
    ContributorAuthor

    Could you try with vscode and tell me of it send didSave when you save a file

    No, it doesn't. Based on this code, I think it relies on save being in the JSON-RPC payload or not.

  13. angelozerr commented on May 30, 2025

    @angelozerr
    Contributor

    Could you try with vscode and tell me of it send didSave when you save a file

    No, it doesn't. Based on this code, I think it relies on save being in the JSON-RPC payload or not.

    If I understand correctly it should not send textDocument/didSave. right?

  14. added a commit that references this issue on May 31, 2025
    b4013e1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions