Vscode-java: Empty responses sent by Java Language Server on almost all actions like autocomplete, definition inspection caused by Apache Flink archetype

Created on 16 Jan 2020  路  9Comments  路  Source: redhat-developer/vscode-java

All code completion, suggestions, definition inspections, etc. are not working because the Java Language Server is returning an empty response on all requests. Important to note is that I'm using VS Code Remote with WSL.

I'm not sure if the problem lies in the extension or the LS. If it becomes obvious that the problem is in the server, I will create a ticket in that repository.

Environment
  • Operating System: Windows 10 (1903) in combination with WSL 1.0 Ubuntu 18.04.3
  • JDK version: 11.0.5 (installed in WSL)
  • Visual Studio Code version: 1.41.1
  • Java extension version: 0.8.1
Steps To Reproduce
  1. Create a simple Java file in WSL
  2. Open VS Code with the remote extension connected to WSL
  3. Open the Java file in VS Code remote
  4. Begin typing any Java code, or hover over any existing Java code
Current Result

In the case of autocompletion, no suggestions in the context of Java code is given. In the case of definition dialogs, these are not even shown. There is no response from VS Code whatsoever.

Expected Result

Autocompletion fields with Java related code is shown; information dialogs when hovering over existing classes is presented. Just generally everything that is shown in the Features GIF in the README.

Additional Informations

The Java Runtime is set to the JDK_HOME path as set in WSL, and it looks like the extension can find and use the runtime.

The (simple) Java project that I'm using for this ticket is the Apache Flink tutorial project (which can be found here). When using the completed code as a reference, one would assume that hovering over simple stuff like StreamExecutionEnvironment would show a definition. Or on a newline start typing Math. would show an autocomplete field with Math methods. However, nothing is shown. When I turn on message tracing between the extension and the LS, I can see that requests are made for every action, but on almost all actions the server returns an empty response.

For example, here is a snippet of several actions:

[Trace - 3:54:12 PM] Sending request 'java/findLinks - (38)'.
Params: {
    "type": "superImplementation",
    "position": {
        "textDocument": {
            "uri": "file:///home/tt/flink-wiki-tutorial/wiki-edits/src/main/java/wikiedits/WikipediaAnalysis.java"
        },
        "position": {
            "line": 10,
            "character": 27
        }
    }
}


[Trace - 3:54:12 PM] Received response 'java/findLinks - (38)' in 4ms.
Result: []


[Trace - 3:54:12 PM] Sending request 'textDocument/documentHighlight - (39)'.
Params: {
    "textDocument": {
        "uri": "file:///home/tt/flink-wiki-tutorial/wiki-edits/src/main/java/wikiedits/WikipediaAnalysis.java"
    },
    "position": {
        "line": 10,
        "character": 28
    }
}


[Trace - 3:54:12 PM] Received response 'textDocument/documentHighlight - (39)' in 3ms.
Result: []


[Trace - 3:54:12 PM] Sending request 'textDocument/codeAction - (40)'.
Params: {
    "textDocument": {
        "uri": "file:///home/tt/flink-wiki-tutorial/wiki-edits/src/main/java/wikiedits/WikipediaAnalysis.java"
    },
    "range": {
        "start": {
            "line": 10,
            "character": 28
        },
        "end": {
            "line": 10,
            "character": 28
        }
    },
    "context": {
        "diagnostics": []
    }
}


[Trace - 3:54:12 PM] Received response 'textDocument/codeAction - (40)' in 3ms.
Result: []


[Trace - 4:06:35 PM] Sending request 'textDocument/codeAction - (41)'.
Params: {
    "textDocument": {
        "uri": "file:///home/tt/flink-wiki-tutorial/wiki-edits/src/main/java/wikiedits/WikipediaAnalysis.java"
    },
    "range": {
        "start": {
            "line": 16,
            "character": 24
        },
        "end": {
            "line": 16,
            "character": 24
        }
    },
    "context": {
        "diagnostics": []
    }
}


[Trace - 4:06:35 PM] Received response 'textDocument/codeAction - (41)' in 4ms.
Result: []


[Trace - 4:11:10 PM] Sending request 'textDocument/codeAction - (42)'.
Params: {
    "textDocument": {
        "uri": "file:///home/tt/flink-wiki-tutorial/wiki-edits/src/main/java/wikiedits/WikipediaAnalysis.java"
    },
    "range": {
        "start": {
            "line": 6,
            "character": 61
        },
        "end": {
            "line": 6,
            "character": 61
        }
    },
    "context": {
        "diagnostics": []
    }
}


[Trace - 4:11:10 PM] Received response 'textDocument/codeAction - (42)' in 5ms.
Result: []

Edit: I should note that I've also tried cleaning the LS workspace directory. Unfortunately, this did not solve my problems.

Most helpful comment

After creating a project from the com.alibaba.blink:flink-quickstart-java:1.5.1 archetype, I managed to reproduce the problem. Whoever created that archetype misunderstands how Maven support works in Eclipse and added some configuration that actually breaks Java support in both Eclipse and vscode-java.

Please remove this snippet from the pom.xml:

<pluginExecution>
    <pluginExecutionFilter>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <versionRange>[3.1,)</versionRange>
        <goals>
            <goal>testCompile</goal>
            <goal>compile</goal>
        </goals>
    </pluginExecutionFilter>
    <action>
        <ignore/>
    </action>
</pluginExecution>

All 9 comments

@testforstephen could you take a look?

@UnrealKazu Could you share the whole log file? You can open the log file via command Java: Open Java language server log file.

@testforstephen No problem, I've create a pastebin with a log of my session today re-creating the bug. As you can see, halfway through the log an exception is logged.

@UnrealKazu thanks for providing the log. Here is my finding:

The Java Home is not correctly configured in the WSL. From the extension log in pastebin, the Java Home read by the extension is /usr/lib/jvm/java-8-openjdk-amd64 (1.8.0_242), not the JDK 11 you mentioned.

There is one exception java.nio.file.ProviderNotFoundException: Provider "jrt" not found. Jrt is introduced by Java 9 and above. Not found in the Jre 8.

To diagnose the Java Runtime issue, please run VS Command via F1 -> Java: Configure Java Runtime.
image

@testforstephen Thanks for looking into the issue. My apologies, I've switched from JDK 11 to JDK 8 after creating this issue due to an (unrelated) dependency problem that required JDK 8.

However, after I've re-installed JDK 11 and set JDK_HOME back to the proper path, all the extension's features started working. I do not know why this was not working when I created the issue, because I did have JDK 11 installed and the JDK_HOME variable was also set to the proper path that time...

For now I'll close this issue as everything seems to be working. I'll keep monitoring if the issue re-appears. Sorry for wasting your time.

Unfortunately the issue has reappeared. I've created a new Maven project and started fleshing out the skeleton classes when I suddenly noticed that the autocomplete etc. was no longer working. A restart of vscode did not solve the issue, neither did a clean operation on the LS workspace. So my original issue has returned.

For completeness sake, I've added a fresh log of both the LS (like requested earlier), as well as a debug log of the message tracing.

No exceptions are shown this time, unfortunately.

Edit: I've narrowed it down to being an issue only appearing whenever I create a Maven project with a specific archetype. If I create a project with either the maven-archetype-quickstart or spring-boot-blank-archetype, the extension's autocompletion works out of the box. However, if I create a project with the flink-quickstart-java archetype (from org.apache.flink), the extension does not work out of the box. So it seems like something in this archetype causes this issue? I can consistently reproduce the issue by creating new projects with these archetypes, so that makes narrowing it down easier.

After creating a project from the com.alibaba.blink:flink-quickstart-java:1.5.1 archetype, I managed to reproduce the problem. Whoever created that archetype misunderstands how Maven support works in Eclipse and added some configuration that actually breaks Java support in both Eclipse and vscode-java.

Please remove this snippet from the pom.xml:

<pluginExecution>
    <pluginExecutionFilter>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <versionRange>[3.1,)</versionRange>
        <goals>
            <goal>testCompile</goal>
            <goal>compile</goal>
        </goals>
    </pluginExecutionFilter>
    <action>
        <ignore/>
    </action>
</pluginExecution>

@fbricon Removing the snippet works, indeed! The same solution works for the Apache archetype (as Alibaba forked it from Apache). I'll open an issue in their repository to discuss whether this is something they want to solve (or mention in the docs).

Thanks for your time!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yaohaizh picture yaohaizh  路  4Comments

danielcalvogonzalez picture danielcalvogonzalez  路  3Comments

roben picture roben  路  4Comments

ViniciusAtaide picture ViniciusAtaide  路  4Comments

gorkem picture gorkem  路  4Comments