neoclide / coc-java

Java extension for coc.nvim
Eclipse Public License 1.0
448 stars 40 forks source link

[coc.nvim]: UnhandledRejection: TypeError: Cannot read properties of null (reading '0') #267

Open sify21 opened 11 months ago

sify21 commented 11 months ago

os

Ubuntu 23.04 (Lunar Lobster)

:CocInfo

## versions

vim version: VIM - Vi IMproved 9.0 9001189
node version: v18.17.1
coc.nvim version: 0.0.82-d1568d56 2023-09-29 19:43:34 +0800
coc.nvim directory: /home/sify/.vim/plugged/coc.nvim
term: dumb
platform: linux

## Log of coc.nvim

2023-10-13T17:14:08.656 INFO (pid:32982) [plugin] - coc.nvim initialized with node: v18.17.1 after 97
2023-10-13T17:14:08.756 ERROR (pid:32982) [server] - unhandledRejection  Promise {
  <rejected> TypeError: Cannot read properties of null (reading '0')
      at lombokPath2Version (/home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:23277:56)
      at lombokPath2VersionNumber (/home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:23281:30)
      at addLombokParam (/home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:23308:35)
      at prepareParams (/home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:23554:5)
      at prepareExecutable (/home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:23478:21)
      at StandardLanguageClient.initialize (/home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:28729:25)
      at async startStandardServer (/home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:29671:3)
      at async /home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:29654:9
} TypeError: Cannot read properties of null (reading '0')
    at lombokPath2Version (/home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:23277:56)
    at lombokPath2VersionNumber (/home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:23281:30)
    at addLombokParam (/home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:23308:35)
    at prepareParams (/home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:23554:5)
    at prepareExecutable (/home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:23478:21)
    at StandardLanguageClient.initialize (/home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:28729:25)
    at async startStandardServer (/home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:29671:3)
    at async /home/sify/.config/coc/extensions/node_modules/coc-java/lib/index.js:29654:9

java-related coc-settings.json

    "java.jdt.ls.java.home": "/home/sify/.asdf/installs/java/temurin-17.0.8+7",
    "java.jdt.ls.vmargs": "-javaagent:/home/sify/.config/coc-lsp/lombok.jar",
    "java.configuration.runtimes": [
        {
            "name": "JavaSE-1.8",
            "path": "/home/sify/.asdf/installs/java/temurin-8.0.382+5"
        },
        {
            "name": "JavaSE-17",
            "path": "/home/sify/.asdf/installs/java/temurin-17.0.8+7",
            "default": true
        }
    ],
ggascon commented 11 months ago

A workaround is to comment this line: "java.jdt.ls.vmargs": "-javaagent:/home/sify/.config/coc-lsp/lombok.jar", in coc-settings.json

sify21 commented 11 months ago

Then how to specify lombok location to coc-java?

Henry-Savary-Jackson commented 10 months ago

Try adding the version number of lombok to the actual lombok jar filename. For example changing "lombok.jar" to "lombok-1.18.28.jar". Make sure to follow to format precisely. Hope this helps! :)

ghost commented 10 months ago

Try adding the version number of lombok to the actual lombok jar filename. For example changing "lombok.jar" to "lombok-1.18.28.jar". Make sure to follow to format precisely. Hope this helps! :)

This is insane. It works.

EvandroLG commented 6 months ago

Wow! It worked out! o.O

trev-dev commented 5 months ago

https://github.com/neoclide/coc-java/blob/master/src/lombokSupport.ts#L24 We're using regex to "validate" the lombok version.

Funny thing is I used nix to supply the lombok, and this regex parsed my javaagent and found the version tag in the path, rather than the filename, and said it was the wrong version.

I think there must be a better way to validate (or not validate) the lombok version.

trev-dev commented 5 months ago

Hey so easy workaround, set this: "java.jdt.ls.lombokSupport.enabled": true - and remove the javaagent flag from the vmargs. I don't remember this working well for myself in the past, but it works now.

Also, if you want to use your own version of lombok, this works: https://github.com/neoclide/coc-java/issues/240#issuecomment-1453010150

medwards commented 5 months ago

Same as trev-dev, I get this error when my settings are:

"java.jdt.ls.lombokSupport.enabled": true,
"java.jdt.ls.vmargs": "-javaagent:/home/medwards/.local/share/lombok/lombok.1.18.24.jar"

Disabling Lombok support ends up working fine.

Removing vmargs will not crash the LSP anymore, but it will not process the lombok annotations either - I have to add the lombok jar to ~/.config/coc/extensions/node_modules/coc-java/lombok/