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

Code Navigation for dependencies

Open csirwin opened this issue 6 years ago • 13 comments

I have a Spring based project and when I try to Ctrl-click to see the source code for a Spring class I get the "Failed to get sources. Instead, stub sources have been generated by the disassembler. Implementation of methods is unavailable." message. I have the sources in my local gradle repo and am wondering how I can get these configured to be able to navigate to the source? I guess the same issue is keeping javadocs for the Spring libraries to be shown also?

Environment
  • Operating System: Windows 10
  • JDK version: 1.8.0_144
  • Visual Studio Code version: 1.23.0
  • Java extension version: 0.25.0
Steps To Reproduce
  1. Load java source with Spring classes being used
  2. Ctrl-click on a Spring class

[attach a sample project reproducing the error] attach logs

Current Result
Expected Result
Additional Informations

csirwin avatar May 25 '18 19:05 csirwin

Most likely, the sources are still being downloaded in the background. Try reopening the project to see if you still see the issue

fbricon avatar May 25 '18 19:05 fbricon

Hi, if it helps,

I can navigate to maven dependency sources, but not to JDK sources.

For example, I can see the source of Spring's MongoTemplate, but not Java's ConcurrentLinkedQueue.

enesaltinkaya avatar May 31 '18 22:05 enesaltinkaya

This is probably an indication that your default Java runtime is either a JRE instead of JDK or a JDK that does not ship the sources. Can you check your JAVA_HOME value and see where it points to?

gorkem avatar Jun 01 '18 00:06 gorkem

I am using "openjdk-8-jdk" package in debian.

Installing "openjdk-8-source" and restarting vscode fixed the issue for me.

Thanks for suggesting "a JDK that does not ship the sources".

(Hayırlı Ramazanlar)

enesaltinkaya avatar Jun 01 '18 13:06 enesaltinkaya

I have the similar question, OS: Ubuntu 18.04 JDK version: 11.04

I configured JAVA_HOME system environment variable, I also installed openjdk-11-source. But if I want to jump to the definition of Class in standard java library, I always get: // Failed to get sources. Instead, stub sources have been generated by the disassembler. // Implementation of methods is unavailable.

praenubilus avatar Oct 24 '18 23:10 praenubilus

I had same case:

When trying to open any JDK class source, the following stacktrace appeared in "Ouput" tab in VS Code:

[Error - 2:24:12 PM] Request textDocument/documentSymbol failed.
  Message: Internal error.
  Code: -32603 
java.util.concurrent.CompletionException: java.lang.NullPointerException
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:314)
	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:319)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:645)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:479)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
Caused by: java.lang.NullPointerException
	at org.eclipse.jdt.ls.core.internal.handlers.DocumentSymbolHandler.getRange(DocumentSymbolHandler.java:174)
	at org.eclipse.jdt.ls.core.internal.handlers.DocumentSymbolHandler.toDocumentSymbol(DocumentSymbolHandler.java:148)
	at org.eclipse.jdt.ls.core.internal.handlers.DocumentSymbolHandler.lambda$2(DocumentSymbolHandler.java:127)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
	at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
	at org.eclipse.jdt.ls.core.internal.handlers.DocumentSymbolHandler.getHierarchicalOutline(DocumentSymbolHandler.java:127)
	at org.eclipse.jdt.ls.core.internal.handlers.DocumentSymbolHandler.documentSymbol(DocumentSymbolHandler.java:72)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$13(JDTLanguageServer.java:557)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$26(JDTLanguageServer.java:764)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
	... 6 more

Other info:

  • Language Support for Java plugin v 0.33.0
  • Ubuntu 18.10 , JDK 11, sudo apt install openjdk-11-source is installed as well.
  • No error, no warning in ~/.config/Code/User/workspaceStorage/1051a_longHash_d8d0a3c/redhat.java/jdt_ws/.metadata/.log
  • disabled gradle setting (aka "java.import.gradle.enabled": false )
  • removed workspace as well (aka https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory )

matihost avatar Nov 01 '18 13:11 matihost

@matihost you can try the solution I found in this thread https://github.com/redhat-developer/vscode-java/issues/689#issuecomment-434046529

praenubilus avatar Nov 01 '18 14:11 praenubilus

Thanks @praenubilus it helped I posted your workaround to Ubuntu bug: https://bugs.launchpad.net/ubuntu/+source/openjdk-lts/+bug/1791219: Symbolic link to src.zip in openjdk-11-source points to an invalid location.

However NPE is NPE, the plugin should at least warn that source were not found under particular location.

matihost avatar Nov 01 '18 14:11 matihost

@matihost It's really annoying. Everytime apt update including openjdk will overwrite the manually created symbolink to the incorrect one again.

praenubilus avatar Nov 01 '18 16:11 praenubilus

I am using "openjdk-8-jdk" package in debian.

Installing "openjdk-8-source" and restarting vscode fixed the issue for me.

Thanks for suggesting "a JDK that does not ship the sources".

(Hayırlı Ramazanlar)

Thanx that helps)

RushOT avatar Feb 05 '20 06:02 RushOT

@matihost you can try the solution I found in this thread #689 (comment)

The root cause is apt creates wrong symbol link and making the sources missing. And this bug can be closed.

akaroml avatar Feb 17 '20 01:02 akaroml

I have encountered a similar problem. Not quite sure if my issue is the same, but after doing mvn compile exec:java mentioned in the Shiro's tutorial on shiro-1.8.0, I get this same error message at the top of the class "org.apache.shiro.config.IniSecurityManagerFactory" (i.e.: //Failed to get sources. Instead, stub sources have been generated by the disassembler). Now when importing this class, it gets crossed out by the vscode and intellisense says: "The type IniSecurityManagerFactory is deprecated", while I'm using the latest version of the Shiro.

aderchox avatar Sep 12 '21 02:09 aderchox

Hi, I was also facing the same issue where when I hover over a function from core java the docs were appearing but when I hovered over a function that came as a part of maven dependency, nothing was showing up.

What is the issue?

sources and javadoc was not getting downloaded when a java/maven project was getting loaded

image

What is the solution?

after setting below two configurations in VS Code settings.json file the VS Code downloads the sources and javadoc while loading a java/maven project

    "java.eclipse.downloadSources": true,
    "java.maven.downloadSources": true,

See the extra steps followed for downloading and associating sources and javadoc in below screenshot:

image

What is the result of all this?

image

Where can we find setting.json file for VS Code?

Press ctrl+shift+p on windows and search for settings, you should see a Preferences: Open Settings (JSON) as shown in below screenshot:

image

Hope it helps 🙂

Asish-Kumar avatar Jun 30 '22 16:06 Asish-Kumar

Close as the problem is resolved.

jdneo avatar Feb 15 '23 07:02 jdneo