vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

The method builder() is undefined for the type xxx

Open f425 opened this issue 1 year ago • 7 comments

demo

env

  • Windows 10
  • JAVA_HOME: C:\Program Files\Java\jdk1.8.0_202
  • Extension: Pack for Java v0.27.0
  • Extension: Language Support for Java(TM) by Red Hat v1.33.0
  • Extension: Gradle for Java v3.16.1
  • jdk1.8.0_202 from Oracle
  • jdk-17.0.12+7 from Adoptium
  • lombok v1.18.12
  • vscode Version: 1.92.0
  • vscode config setting.json about java and gradle:
    1. C:\\Program Files\\Java\\jdk1.8.0_202 (Oracle jdk8 for code project)
    2. C:\\Program Files\\Eclipse Adoptium\\jdk-17.0.12+7 (for vscode language server)
        {
            "java.jdt.ls.java.home": "C:\\Program Files\\Eclipse Adoptium\\jdk-17.0.12+7",
            "java.import.gradle.java.home": "C:\\Program Files\\Java\\jdk1.8.0_202",
            "java.configuration.runtimes": [
                {
                    "name": "JavaSE-1.8",
                    "path": "C:\\Program Files\\Java\\jdk1.8.0_202",
                    "default": true
                }
            ]
        }
    

problem

  1. after upgrade Extension: Language Support for Java(TM) by Red Hat to v1.33.0. Got error:
[{
	"resource": "/c:/Users/ww/work/test/project-for-test/test2/src/main/java/com/test2/Test2.java",
	"owner": "_generated_diagnostic_collection_name_#5",
	"code": "67108964",
	"severity": 8,
	"message": "The method builder() is undefined for the type Data1",
	"source": "Java",
	"startLineNumber": 9,
	"startColumn": 15,
	"endLineNumber": 9,
	"endColumn": 22
}]
  1. Change Extension: Language Support for Java(TM) by Red Hat to v1.32.0. It's OK.
  2. Keep Extension: Language Support for Java(TM) by Red Hat with v1.33.0.
    • copy Data1.java to Data2.java and delete comments.
    • Data2.builder().build() is ok

image

f425 avatar Aug 02 '24 03:08 f425

There seem to be several issues related (or unrelated) to the Javadoc comments of the @Builder class in the latest Lombok 1.18.34. (issue 1, issue 2)

The version of Lombok bundled in this extension is from https://projectlombok.org/lombok-edge.jar, which currently delivers the same binary as Lombok 1.18.34, thereby affecting this extension.

Temporary solutions I discovered:

  • Downgrade this extension to v1.32.0
  • Or use the lombok/lombok-1.18.33.jar bundled in v1.32.0
    • Overwrite the jar file in the same path of the current version, or build and install the .vsix file yourself
Steps to overwrite

Windows PowerShell environment:

# Get and extract vscode-java v1.32.0 binary
curl.exe -LO "https://github.com/redhat-developer/vscode-java/releases/download/v1.32.0/vscode-java-1.32.0-220.vsix"
Rename-Item "vscode-java-1.32.0-220.vsix" "vscode-java-1.32.0-220.vsix.zip"
Expand-Archive -Path ".\vscode-java-1.32.0-220.vsix.zip" -DestinationPath ".\temp_ext"

# Copy .jar file
Copy-Item "temp_ext/extension/lombok/lombok-1.18.33.jar" "$env:userprofile/.vscode/extensions/redhat.java-1.33.0-win32-x64/lombok/lombok-1.18.33.jar"

# Remove downloaded files
Remove-Item -Recurse -Path "temp_ext","vscode-java-1.32.0-220.vsix.zip"

Linux-like environment:

# Get and extract vscode-java v1.32.0 binary
curl -LO https://github.com/redhat-developer/vscode-java/releases/download/v1.32.0/vscode-java-1.32.0-220.vsix
# or wget:
# wget https://github.com/redhat-developer/vscode-java/releases/download/v1.32.0/vscode-java-1.32.0-220.vsix
unzip -d temp_ext/ vscode-java-1.32.0-220.vsix

# Copy .jar file
# Replace .vscode with .vscode-server if you're in remote environment (like wsl, docker or ssh)
cp temp_ext/extension/lombok/lombok-1.18.33.jar /home/$(whoami)/.vscode/extensions/redhat.java-1.33.0*/lombok/lombok-1.18.33.jar

# Remove downloaded files
rm -rf /tmp/temp_ext vscode-java-1.32.0-220.vsix

heguro avatar Aug 02 '24 10:08 heguro

@heguro Lombok version is 1.18.12 in my demo project. Before this extension v1.33.0, it was working fine.

f425 avatar Aug 03 '24 06:08 f425

image image image

f425 avatar Aug 05 '24 06:08 f425

Is it fixed in the latest version

iwangbowen avatar Aug 16 '24 13:08 iwangbowen

Which version are you referring? I have the Language Support for Java(TM) by Red Hat v1.35.202408 and the bug is still there.

foxpluto avatar Sep 01 '24 08:09 foxpluto

when this will be fixed

iwangbowen avatar Sep 15 '24 08:09 iwangbowen

Lombok has merged a fix as of a few days ago (see https://github.com/projectlombok/lombok/pull/3726), but they have not done a release yet. So I assume that will have to happen first so that an updated version of Lombok can be bundled with the extension.

Kas-tle avatar Sep 15 '24 12:09 Kas-tle

https://github.com/redhat-developer/vscode-java/issues/3561#issuecomment-2442023671 woke me up. Could someone try the vscode-java pre-release and see if the problem is resolved ? According to https://github.com/redhat-developer/vscode-java/blob/0f89a67eaf7a0189e3da172a02e277d128a96cc7/gulpfile.js#L132 (the 1.18.33 label we give is wrong, but it's definitely the latest), we're using the latest lombok edge release, which is from 2024-10-18. That definitely should have the fix. If it doesn't work then the problem was never fixed by the PR.

rgrunber avatar Oct 28 '24 18:10 rgrunber

With the currently used Lombok v1.18.34 this is still an issue. Updating to v1.18.36 should fix it (relevant commit: https://github.com/projectlombok/lombok/commit/1ac3950a9e8d1c2da0ff0d6400386a9b345b23a2). At least it did so for the Eclipse IDE.

NicoFraenzel avatar Jan 30 '25 12:01 NicoFraenzel