Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java-language-server throws exception #2769

Closed
GLaDOS-418 opened this issue Aug 21, 2023 · 4 comments
Closed

java-language-server throws exception #2769

GLaDOS-418 opened this issue Aug 21, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@GLaDOS-418
Copy link

Description

java-language-server throws exception on opening java file from inside a java project.

the server is installed via mason.nvim plugin.

Neovim version

Tried with two nvim versions:

NVIM v0.10.0-dev-585+g2e055e49a
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3

Nvim-lspconfig version

No response

Operating system and version

Ubuntu 23.04

Affected language servers

java-language-server

Steps to reproduce

  1. open a random .java file from a java project in nvim using the minimal config.
  2. wait for the exception in messages.

I tried with the following projects:

  1. https://github.com/openjdk/jdk
  2. https://github.com/pubnub/java

Actual behavior

exception 1 : project openjdk/jdk

there's an exception in the messages:

Error executing vim.schedule lua callback: /home/helix/.local/nvim/share/nvim/runtime/lua/vim/lsp.lua:1413: RPC[Error] code_name = InternalError, message = "java.nio.charset.MalformedInputException: Input length = 1"
stack traceback:
        [C]: in function 'assert'
        /home/helix/.local/nvim/share/nvim/runtime/lua/vim/lsp.lua:1413: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
Press ENTER or type command to continue

here's the lsp log for this scenario.

exception 2: project pubnub/java

in this project, I get a different exception:

Error executing vim.schedule lua callback: .../.local/nvim/share/nvim/runtime/lua/vim/lsp/_dynamic.lua:42: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
        [C]: in function 'ipairs'
        .../.local/nvim/share/nvim/runtime/lua/vim/lsp/_dynamic.lua:42: in function 'unregister'
        .../.local/nvim/share/nvim/runtime/lua/vim/lsp/_dynamic.lua:29: in function 'register'
        .../.local/nvim/share/nvim/runtime/lua/vim/lsp/handlers.lua:114: in function 'handler'
        /home/helix/.local/nvim/share/nvim/runtime/lua/vim/lsp.lua:1155: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

and then the server starts. Here's the lsp log for the second scenario.

Expected behavior

the server provides proper outputs without any exceptions.

Minimal config

local on_windows = vim.loop.os_uname().version:match 'Linux'

local function join_paths(...)
  local path_sep = on_windows and '\\' or '/'
  local result = table.concat({ ... }, path_sep)
  return result
end

vim.cmd [[set runtimepath=$VIMRUNTIME]]

local temp_dir = vim.loop.os_getenv 'TEMP' or '/tmp'

vim.cmd('set packpath=' .. join_paths(temp_dir, 'nvim', 'site'))

local package_root = join_paths(temp_dir, 'nvim', 'site', 'pack')
local lspconfig_path = join_paths(package_root, 'test', 'start', 'nvim-lspconfig')

if vim.fn.isdirectory(lspconfig_path) ~= 1 then
  vim.fn.system { 'git', 'clone', 'https://github.com/neovim/nvim-lspconfig', lspconfig_path }
end

vim.lsp.set_log_level 'trace'
require('vim.lsp.log').set_format_func(vim.inspect)
local nvim_lsp = require 'lspconfig'
local on_attach = function(_, bufnr)
  local function buf_set_option(...)
    vim.api.nvim_buf_set_option(bufnr, ...)
  end

  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

  -- Mappings.
  local opts = { buffer = bufnr, noremap = true, silent = true }
  vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
  vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
  vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
  vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
  vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
  vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
  vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
  vim.keymap.set('n', '<space>wl', function()
    print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
  end, opts)
  vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
  vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
  vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
  vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
  vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
  vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
  vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
end

-- Add the server that troubles you here
local name = 'java_language_server'
local cmd = { '/home/helix/.local/share/nvim/mason/packages/java-language-server/dist/lang_server_linux.sh' }
if not name then
  print 'You have not defined a server name, please edit minimal_init.lua'
end
if not nvim_lsp[name].document_config.default_config.cmd and not cmd then
  print [[You have not defined a server default cmd for a server
    that requires it please edit minimal_init.lua]]
end

nvim_lsp[name].setup {
  cmd = cmd,
  on_attach = on_attach,
}

print [[You can find your log at $HOME/.cache/nvim/lsp.log. Please paste in a github issue under a details tag as described in the issue template.]]

LSP log

https://gist.github.com/GLaDOS-418/70420e34b2b09214a2993f3764a64f08

@YaBoich
Copy link

YaBoich commented Aug 23, 2023

Having the same issue.

@justinmk
Copy link
Member

Thanks for your report. This is not a support channel.

The configs in this repo are unsupported and provided only as a starting point. We depend on users (like you) to troubleshoot issues with their specific LSP setups and send improvements.

If you found a bug in the core Nvim vim.lsp module (not part of this repo), the best way to get it fixed is to report to Nvim (not nvim-lspconfig) with:

  • steps to reproduce it without the particular LSP server and other factors particular to your environment
  • (optional, but very helpful): by adding a failing test case to lsp_spec.lua, which has code to setup a fake LSP server to simulate various scenarios

@justinmk justinmk closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2023
@ciceropaulino
Copy link

Same problem here after install java-language-server using mason in the LazyVim

@thatsmydoing
Copy link

It seems this is a bug with the language server itself, though it can be worked around georgewfraser/java-language-server#267

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants