redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.08k stars 440 forks source link

Usage of java VScode extension in multiple containers setup #1801

Closed veredcon closed 9 months ago

veredcon commented 3 years ago
Environment
Steps To Reproduce

I cannot provide steps to reproduce as this issue happens in our special setup Web IDE where we use multiple docker containers and the JDK is installed in a different container from where the vscode-java extension runs.

The version we used so far is 0.46.0 which worked fine, and now we are facing some obstacles when trying to upgrade. We managed to pass the activation phase of the VScode extension, using JDK 11, however encountered LSP issues in our environment.

For example: root INFO [hosted-plugin: 66824] { message: '[Info - 3:45:03 PM] Feb 7, 2021, 3:45:03 PM Implicit super constructor Object() is undefined for default constructor. Must define an explicit constructor is of type UndefinedConstructorInDefaultConstructor', level: 'info', timestamp: '2021-02-07 15:45:03.783' } And there is an issue to find basic types (like Integer/String) so seems like some configuration went wrong on the way:

image

After extensive investigation in the frontend and server code, we found that this piece of code causes these LSP errors: https://github.com/eclipse/eclipse.jdt.ls/commit/7a0872bdef3ef7751da9a90021c43e14ee85e446#diff-0ef00af71cdc38cf5969fb55251c0b924ceb64d6c88727308683209ffa773ea7R117-R125 https://github.com/eclipse/eclipse.jdt.ls/blob/8028f3ffc04e7f4695ffa08d058912e2003a0116/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BaseInitHandler.java#L117-L124 (master code)

More info on the settings.json we use:

  1. If we don't add in our theia based IDE the "java.home" explicitly in the settings.json, the extension won't be activated since there is a different logic in case "java.home" is not in the settings, then it searches it in JDK_HOME, JAVA_HOME etc. and goes to verifyJavaHome which calls findLinkedFile but this causes issues in our case since /home/user/java11 is just a symbolic link to where the java is really located (in other docker container).
  2. If we do add it, the settings.json looks like this and the extension is being activated: "java.jdt.ls.vmargs": "-DwatchParentProcess=false -noverify -XX:MaxDirectMemorySize=10M XX:MaxMetaspaceSize=98632K -Xss1M -Xmx437943K -XX:+UseG1GC -XX:+UseStringDeduplication", "java.configuration.checkProjectSettingsExclusions": false, "java.configuration.updateBuildConfiguration": "automatic", "java.autobuild.enabled": false, "java.home": "/home/user/java11",

Attached are the client and server logs in this case of:

  1. 0.46.0 - version we used and always worked. (only 1 log file was available in that version) server0.46.0-works-ok.txt

  2. 0.53.1 - still working version (client+server) client0.53.1-works-ok.txt server.0.53.1-works-ok.txt

  3. 0.74.0 - logs of not working version (client+server) server-0.74.0-not-working.log.txt client-0.74.0-not-working.log.txt

  4. master code (0.75.0) which I built with the server modification I mentioned, commented out the configureJVMs, added this note also in a log with prefix "VERED". In this case it work OK for us. client-0.74.0-work-ok--isworkspaceinitialized-comment.log.txt

Current Result

Java LS does not recognized our JDK and as a result we get basic errors as the screenshot and logs.

Expected Result

To have some kind of workaround/ configurable settings to allow us bypass the errors. For example, if we are not entering the code of isWorkspaceInitialized=false (configureJVMs) we are OK. Can we control this value?

Additional Informations
fbricon commented 3 years ago

@snjeza might be the server doesn't cope well when initialization options are missing/incomplete. Please investigate.

fbricon commented 3 years ago

@snjeza "Default VM Install changed from 1612768316552-/usr/lib/sapmachine-jdk/sapmachine-jdk-11.0.6.0.1 to 1612768316579-/home/user/java11'," might be the cause, the new location might not be reachable

snjeza commented 3 years ago

@veredcon could you try to add

"java.server.launchMode": "Standard",

to your settings.json

veredcon commented 3 years ago

Hello @snjeza ,

Thanks for taking a look into this issue. I've already tried that and it still doesn't work. Attached are the logs with this settings configured.

client0.74.0-standard-not-working.txt server0.74.0-standard-not-working.txt

As this upgrade is a top priority task for us, could it be helpful if we even set a meeting and I'll show you our setup and all? I believe it make things harder that you cannot really reproduce this issue in your environment.

When I looked at the logs and code I could notice that when we enter configureDefaultVM and it returns changed=true things goes wrong. when it returns changed=false everything is OK and no errors appears.

So, when looking at the logic there, the jvmHome ="/home/user/java11" and the defaultVM=/usr/lib/sapmachine-jdk/sapmachine-jdk-11.0.6.0.1 are not equal so it doesn't return false but continues. I'm not sure how to control the result of the defaultVM and how it gets this value but this path does not exist and is not reachable from the container where the extension runs.

Here is a screenshot of how things built in our environment: image

  1. /home/user/java11 is accessible to some point but all inner executables (java/javac) are symbolic links to other containers.
  2. We do have JDK 11 in our enviornment
  3. The path "/usr/lib/sapmachine-jdk/sapmachine-jdk-11.0.6.0.1" does not exist.

Please let me know if you need more information / even prefer setting a short meeting. Thanks a lot in advance! Vered

veredcon commented 3 years ago

Additional info - now I noticed that even when the isWorkspaceInitialized code is commented out, it works only in LightWight Mode and not in Standard mode... I attached these logs just in case... these are the logs of vsix which I commented out this code: image

075withpatch-lw-standard.txt server075withpatch-lw-standard.txt

snjeza commented 3 years ago

@veredcon you can try

"java.configuration.runtimes": [
        {
            "name": "JavaSE-11",
            "path": "/home/user/java11",
            "default": true
        }
    ],
veredcon commented 3 years ago

Thanks @snjeza , Yes I tries that too and got another error :( image

So with these settings: image

We get the following logs: client074withruntime.txt server074withruntime.txt

Thanks!

snjeza commented 3 years ago

Here is a screenshot of how things built in our environment:

$ cd /user/home/java11
$ ls
bin

JAVA_HOME has been incorrectly configured. It should look like the following:

$ ls -la sapjava11
lrwxrwxrwx. 1 snjeza snjeza 34 Feb  8 19:15 sapjava11 -> /usr/local/sapmachine-jdk-11.0.10/
$ ls -la sapjava11/
total 40
drwxr-xr-x.  9 root root 4096 Feb  8 19:05 .
drwxr-xr-x. 50 root root 4096 Feb  8 19:05 ..
drwxr-xr-x.  2 root root 4096 Feb  8 19:05 bin
drwxr-xr-x.  4 root root 4096 Feb  8 19:05 conf
drwxr-xr-x.  3 root root 4096 Feb  8 19:05 include
drwxr-xr-x.  2 root root 4096 Feb  8 19:05 jmods
drwxr-xr-x. 73 root root 4096 Feb  8 19:05 legal
drwxr-xr-x.  6 root root 4096 Feb  8 19:05 lib
drwxr-xr-x.  4 root root 4096 Feb  8 19:05 man
-rw-r--r--.  1 snjeza snjeza 1229 Jan 19 23:08 release
veredcon commented 3 years ago

Hi @snjeza

In our JAVA_HOME is pointing to /home/user/java11 and has only link to bin. Do you mean that it has to include other folders like conf, lib etc. because you rely on them in your logic?

As we saw in the logs, JavaRuntime.getDefaultVMInstall().getInstallLocation() returns /usr/lib/sapmachine-jdk/sapmachine-jdk-11.0.6.0.1 and we don't want the change to /home/user/java11 to happen. We want the server to continue look on the path /usr/lib/sapmachine-jdk/sapmachine-jdk-11.0.6.0.1 because in that case it seems to work fine.

Since the "patch" I did in the server did not work in all launchModes (only in LightWeight) I tried another way to prevent this changing in configuration in the server to happen - In the vscode extension itself, in the extension.ts file, I forced the java.home being passed to the server to be null. All other properties will still be passed as is.

image

In that case, the server is getting java.home=null and I guess uses some default so that's the reason it still works:

!MESSAGE >> New configuration: {java={home=null, jdt={ls={vmargs=-DwatchParentProcess=false -noverify -XX:MaxDirectMemorySize=10M -XX:MaxMetaspaceSize=98632K -Xss1M -Xmx437943K -XX:+UseG1GC -XX:+UseStringDeduplication}}, errors={incompleteClasspath={severity=warning}}, configuration={checkProjectSettingsExclusions=false, updateBuildConfiguration=automatic, maven={userSettings=null, globalSettings=null}, runtimes=[]}, trace={server=off}, import={maven={enabled=true}, gradle={enabled=true, wrapper={enabled=true}, version=null, home=null, java={home=null}, offline={enabled=false}, arguments=null, jvmArguments=null, user={home=null}}, exclusions=[/node_modules/, /.metadata/, /archetype-resources/, /META-INF/maven/]}, maven={downloadSources=false, updateSnapshots=false}, eclipse={downloadSources=false}, referencesCodeLens={enabled=false}, signatureHelp={enabled=false}, implementationsCodeLens={enabled=false}, format={enabled=true, settings={url=null, profile=null}, comments={enabled=true}, onType={enabled=true}}, saveActions={organizeImports=false}, project={referencedLibraries=[lib/*/.jar], importOnFirstTimeStartup=interactive, importHint=true, resourceFilters=[node_modules, .git]}, contentProvider={preferred=null}, autobuild={enabled=false}, maxConcurrentBuilds=1.0, completion={maxResults=0.0, enabled=true, overwrite=true, guessMethodArguments=false, favoriteStaticMembers=[org.junit.Assert., org.junit.Assume., org.junit.jupiter.api.Assertions., org.junit.jupiter.api.Assumptions., org.junit.jupiter.api.DynamicContainer., org.junit.jupiter.api.DynamicTest., org.mockito.Mockito., org.mockito.ArgumentMatchers., org.mockito.Answers.], filteredTypes=[java.awt., com.sun., sun.], importOrder=[java, javax, com, org]}, foldingRange={enabled=true}, progressReports={enabled=true}, codeGeneration={hashCodeEquals={useJava7Objects=false, useInstanceof=false}, useBlocks=false, generateComments=false, toString={template=${object.className} [${member.name()}=${member.value}, ${otherMembers}], codeStyle=STRING_CONCATENATION, skipNullValues=false, listArrayContents=true, limitElements=0.0}}, selectionRange={enabled=true}, showBuildStatusOnStart={enabled=false}, server={launchMode=Standard}, sources={organizeImports={starThreshold=99.0, staticStarThreshold=99.0}}, semanticHighlighting={enabled=true}, refactor={renameFromFileExplorer=prompt}, imports={gradle={wrapper={checksums=[]}}}, templates={fileHeader=[], typeComment=[]}, references={includeAccessors=true}}}

Full Logs of that path: client074-with-frontend-patch.txt server074-with-frontend-patch.txt

Is there some configuration/workaround to force the LS not to change the configuration?

snjeza commented 3 years ago

In our JAVA_HOME is pointing to /home/user/java11 and has only link to bin. Do you mean that it has to include other folders like conf, lib etc. because you rely on them in your logic?

Right. Eclipse JDT requires a valid JDK.

We want the server to continue look on the path /usr/lib/sapmachine-jdk/sapmachine-jdk-11.0.6.0.1 because in that case it seems to work fine.

you can try

"java.configuration.runtimes": [
        {
            "name": "JavaSE-11",
            "path": "/usr/lib/sapmachine-jdk/sapmachine-jdk-11.0.6.0.1",
            "default": true
        }
    ],

/usr/lib/sapmachine-jdk/sapmachine-jdk-11.0.6.0.1 have to have a valid JDK.

Is there some configuration/workaround to force the LS not to change the configuration?

You should start Java LS with a valid JDK. /usr/lib/sapmachine-jdk/sapmachine-jdk-11.0.6.0.1 is hidden, /user/home/java11 is incomplete.

snjeza commented 3 years ago

@veredcon You can see how che creates a java sidecar - https://github.com/eclipse/che-plugin-registry/tree/master/sidecars/java

/projects $ echo $JAVA_HOME
/usr/lib/jvm/default-jvm/
/projects $ ls $JAVA_HOME
ASSEMBLY_EXCEPTION  bin                 include             legal               release
LICENSE             conf                jmods               lib
README              demo                jre                 man
/projects $ 

che

veredcon commented 3 years ago

@snjeza Thank you so much for the suggestion! that worked!

"java.configuration.runtimes": [
        {
            "name": "JavaSE-11",
            "path": "/usr/lib/sapmachine-jdk/sapmachine-jdk-11.0.6.0.1",
            "default": true
        }
    ],

together with the java.home settings!

Thanks a lot for your time and help! 🙏🎉👏

veredcon commented 3 years ago

Hi @snjeza , Why this vsix is not available in this link? https://github.com/redhat-developer/vscode-java/releases/download/v0.75.0/redhat.java-0.75.0.vsix Since 0.61.0 seems you stopped the upload vsixs to the releases.

Can you load the vsix so it will be available?

Thanks!

fbricon commented 3 years ago

@veredcon in the meantime, you can download it from one of those 2 marketplaces

veredcon commented 3 years ago

Cool! We will download it from open-vsx, thanks a lot!

apupier commented 3 years ago

@veredcon Do you still have issues or you were abel to handle what you wanted?