vscode-java: Version 1.2.0 doesn't detect JDK installed via Homebrew well

I’ve been using the extension for some time now. A couple of days ago, I’ve updated it to 1.2.0 and since then, when opening a study project it would report errors for everything.

Some of the errors include not finding Object’s default no args constructor, failing to import basic core classes from Java (i.e. java.util, java.date), and so on.

I’ve already removed my JDK 17 installation, replacing it with JDK 11, and that had no effect. Only fix I’ve found is to rollback the extension to the previous version (1.1.0, from 3w ago).

Some screenshots are attached to show the errors I’m facing.

Environment
  • Operating System: macOS 12.1 Monterey arm64 (Apple Silicon)
  • JDK version: openjdk version “17.0.1” 2021-10-19, installed via Homebrew
  • Visual Studio Code version: 1.63.2 (Universal)
  • Java extension version: 1.2.0
Steps To Reproduce
  1. Clone example project
  2. Open project folder in VS Code
  3. Open any .java file

Example project: https://github.com/brunovieira97/alura-novidades-java

Logs: Logs.zip

Current Result

image image image image

Expected Result (v1.1.0)

image

Additional Informations
  • Reinstalling the extension had no effect
  • Tried removing VS Code completely and reinstalling as well
  • As previously stated, I removed openjdk via brew and installed openjdk@11, properly linking it. No effect at all
  • Log for "Language Support for Java (Syntax Server) shows this message, both with 1.1.0 and 1.2.0:
[Error - 13:29:00] Connection to server got closed. Server will not be restarted.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

@testforstephen was able to test today and it’s working as expected now. Thank you for fixing this so fast, everyone!

Homebrew creates a lot of symbolic links, I find we can only rely on <some-path>/bin/java, which is finally linked to the real installation location.

I’ve covered this case in latest jdk-utils. If you have a NodeJS runtime, you can run below command to test if your installed JDK is detected.

npx jdk-utils@0.4.1

Below is my smoke test.

$> ls -l /usr/local/opt/ | grep jdk
lrwxr-xr-x  1 sechs  admin  24 Dec 10  2020 java -> ../Cellar/openjdk/15.0.1
lrwxr-xr-x  1 sechs  admin  28 Dec 20 21:31 java11 -> ../Cellar/openjdk@11/11.0.12
lrwxr-xr-x  1 sechs  admin  24 Dec 10  2020 openjdk -> ../Cellar/openjdk/15.0.1
lrwxr-xr-x  1 sechs  admin  28 Dec 20 21:31 openjdk@11 -> ../Cellar/openjdk@11/11.0.12
lrwxr-xr-x  1 sechs  admin  24 Dec 10  2020 openjdk@15 -> ../Cellar/openjdk/15.0.1

$> cd /usr/local/opt/openjdk
$> ls -l bin/java
lrwxr-xr-x  1 sechs  staff  45 Sep 12  2020 bin/java -> ../libexec/openjdk.jdk/Contents/Home/bin/java

$> export PATH=/usr/local/opt/openjdk/bin:$PATH

$> npx jdk-utils@0.4.1
...
  {
    homedir: '/usr/local/Cellar/openjdk/15.0.1/libexec/openjdk.jdk/Contents/Home',
    isInPathEnv: true,
    hasJavac: true,
    version: { java_version: '15.0.1', major: 15 }
  },
  {
    homedir: '/usr/local/Cellar/openjdk@11/11.0.12/libexec/openjdk.jdk/Contents/Home',
    hasJavac: true,
    version: { java_version: '11.0.12', major: 11 }
  }
...

UPDATE

I just find on https://docs.brew.sh/Installation, location of homebrew is different per platform.

  • /usr/local for macOS Intel, covered in jdk-utils@0.4.1.
  • /opt/homebrew for Apple Silicon, which is @brunovieira97 's case.
  • /home/linuxbrew/.linuxbrew for Linux. Later I’ll cover all above cases in jdk-utils, and create a PR then.

Could you try the following:

$ export JAVA_HOME=/opt/homebrew/opt/openjdk
$ export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"
$ ls $JAVA_HOME/bin/javac
$ javac -version
$ cd <your alura-novidades-java>
$ code .

@brunovieira97 https://download.jboss.org/jbosstools/jdt.ls/staging/java-1.3.0-491/ has fixed this issue, pls try to download the new extension version java-darwin-arm64-1.3.0-491.vsix for Apple M1, and manually install the vsix to VS Code.

@Eskibear This is a new corner case that the new findJavaHome lib jdk-utils needs to cover better. https://github.com/Eskibear/node-jdk-utils/issues/2

The problem is clearly related to v1.2.0 of the extension. If I rollback to 1.1.0, as I said, no problems are reported for the source files.

I can’t reproduce it. Could you try the latest build - https://download.jboss.org/jbosstools/jdt.ls/staging/java-1.3.0-490/java-1.3.0-490.vsix