Skip to content

Uncaught exception: 'java.project.listSourcePaths' already exists #2331

Closed

Description

@davidpcaldwell

When developing my own extension and running it under the Extension Development Host in the debugger (I have it set to pause on uncaught exceptions), on opening a Java project (with this extension installed), I am getting the following stack trace:

Exception has occurred: Error: command 'java.project.listSourcePaths' already exists
t u.registerCommand ([/Users/inonit/Applications/Visual]() Studio Code.app[/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:93:28683]())
	at Object.registerCommand ([/Users/inonit/Applications/Visual]() Studio Code.app[/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:107:30423]())
	at X.register ([/Users/inonit/.vscode/extensions/redhat.java-1.3.0/dist/extension.js:2:945419]())
	at [/Users/inonit/.vscode/extensions/redhat.java-1.3.0/dist/extension.js:2:966900]()
	at new Promise (<anonymous>)
	at w.handleRegistrationRequest ([/Users/inonit/.vscode/extensions/redhat.java-1.3.0/dist/extension.js:2:966543]())
	at [/Users/inonit/.vscode/extensions/redhat.java-1.3.0/dist/extension.js:2:957330]()
	at [/Users/inonit/.vscode/extensions/redhat.java-1.3.0/dist/extension.js:2:1106102]()
	at [/Users/inonit/.vscode/extensions/redhat.java-1.3.0/dist/extension.js:2:1107161]()
	at Immediate._onImmediate ([/Users/inonit/.vscode/extensions/redhat.java-1.3.0/dist/extension.js:2:1109867]())
	at processImmediate (internal[/timers.js:461:21]())
	at process.callbackTrampoline (internal[/async_hooks.js:131:14]())```

##### Environment
- Operating System: macOS (10.15.7 and 12.2.1)
- JDK version: Oracle JDK 1.8.0_212 and AdoptOpenJDK 11.0.8
- Visual Studio Code version: 1.64.2
- Java extension version: 1.3.0

##### Steps To Reproduce
1. Open Extension Development Host with my (unpublished) extension and with a window containing Java projects
2. Wait. I don't know the API well enough to know whether this is on a timer (the stack trace may suggest this) or whether it's more complicated than that (`processImmediate` is maybe just something to do with the event loop)?

##### Current Result
See stack trace of uncaught exception above.

##### Expected Result
No uncaught exception.

##### Additional Informations
![Screen Shot 2022-02-23 at 2 26 38 PM](https://user-images.githubusercontent.com/1809061/155395932-3a03d2f6-e15e-432d-8866-12721772c8b3.png)

Activity

  1. rgrunber commented on Feb 24, 2022

    @rgrunber
    Member

    I see it as well

    Exception has occurred: Error: command 'java.project.listSourcePaths' already exists
    t u.registerCommand ([/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:93:28683]())
    	at Object.registerCommand ([/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:107:30423]())
    	at ExecuteCommandFeature.register ([/home/rgrunber/git/vscode-java/dist/extension.js:79361:52]())
    	at [/home/rgrunber/git/vscode-java/dist/extension.js:80279:29]()
    	at new Promise (<anonymous>)
    	at LanguageClient.handleRegistrationRequest ([/home/rgrunber/git/vscode-java/dist/extension.js:80265:16]())
    	at [/home/rgrunber/git/vscode-java/dist/extension.js:79913:108]()
    	at handleRequest ([/home/rgrunber/git/vscode-java/dist/extension.js:89822:41]())
    	at processMessageQueue ([/home/rgrunber/git/vscode-java/dist/extension.js:89686:17]())
    	at Immediate._onImmediate ([/home/rgrunber/git/vscode-java/dist/extension.js:89676:13]())
    	at processImmediate (internal[/timers.js:461:21]())
    	at process.callbackTrampoline (internal[/async_hooks.js:131:14]())
    

    It seemed the stacktrace was associated with the language server registering commands to the client side, so I recalled we have https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/plugin.xml#L54-L106 in JDT-LS. Any command there that's also registered on the client side (eg. https://github.com/redhat-developer/vscode-java/blob/master/src/buildpath.ts#L48) would run into this.

    @fbricon @snjeza , is there a reason we register in both places ?

    Looks to me like we have a command on the client side that is just meant to call the same command on the server side. Maybe just using a slightly different name would avoid the clash.

  2. rgrunber commented on Feb 28, 2022

    @rgrunber
    Member

    I don't think the exception results in any unwanted behaviour, though I have a simple patch to fix it. I think the issue happens as follows :

    We register a command on the client-side (eg. https://github.com/redhat-developer/vscode-java/blob/master/src/buildpath.ts#L48-L49) that simply calls java.execute.workspaceCommand on the server side with the same named command id. That command id is also registered by the server to the client. See https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java#L350-L351 & https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/plugin.xml#L74 .

    The client side is registered first and the server side fails to register its command (already exists). However, I don't think this is an issue because we call the server side commands through `java.execute.workspaceCommand , and not directly.

    Update : Yup, https://github.com/microsoft/vscode-languageserver-node/blob/main/client/src/common/client.ts#L2887-L2891 handles the registration of the commands passed to workspace/executeCommand coming from the server. It registers a command with the same ID. So one could do vscode.commands.executeCommand(ID) or vscode.commands.executeCommand("java.workspace.executeCommand", ID) and both should work.

  3. added a commit that references this issue on Mar 9, 2022
    29b1ae7
  4. added a commit that references this issue on Mar 16, 2022
    55ccfb6
  5. added this to the End March 2022 milestone on Mar 16, 2022
  6. added a commit that references this issue on Mar 16, 2022
    ca9e8cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions