M BUZZ CRAZE NEWS
// general

vscode code navigation "Failed to get sources."

By David Jones

I am using VSCODE to develop codes in Java with "Java Extension Pack". I encountered the issue that the code navigation of vscode doesn't work as expected.

Previously, I can use "Ctrl+Click"(please see the description: ) to check the definitions from Java packages, such as java.util.HashMap etc.

However, after re-install my OS, the code navigation didn't work as expected. Unlike some posts online(please see or ), in my case, it works but it shows .class file with such comments on the top of the file. Let me use the Hashmap as the example.

/* HashMap.class */

// Failed to get sources. Instead, stub sources have been generated by the disassembler.
// Implementation of methods is unavailable.
package java.util;
public class HashMap<K,V> extends java.util.AbstractMap implements java.util.Map, java.lang.Cloneable, java.io.Serializable { // many declartions for methods below ... }

What I need is navigating to the HashMap.java rather than HashMap.class. I use "Setting Sync" extension which restores all my previous settings, so I don't think there are any issues about my setting. I still will provide some related User settings below

 "java.classPath": [], // Specifies the folder path to the JDK (8 or more recent) used to launch the Java Language Server. "java.home": null, // Installation directory of Java 8 "java.home": "", // Traces the communication between VS Code and the Java language server. "java.trace.server": "off",

More info:

OS: Ubuntu 18.04 LTS

VSCODE version: 1.22.2

openjdk version "1.8.0_162"

Any help will be appreciated! Thank yoU!

2 Answers

For ubuntu users, you could try the command line below

sudo apt install openjdk-{jdk version}-source
2

I had the same error, except with a source jar in my local repository rather than HashMap.

I fixed it by quitting Visual Studio Code, removing all the .classpath, .factorypath, and .project files (my project has submodules so there are multiple of these), then reopening VS Code and letting it find everything again.

There's likely a more elegant way to do this but brute force worked.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy