Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Source code not showing (IntelliJ?)

I'm using IntelliJ and developing code using Java.

When I use "Go to Declaration" [Ctrl+B] to a Java inbuilt feature (e.g. ArrayList), it takes me to that class (e.g. ArrayList.class) and looks a bit like this:

// IntelliJ API Decompiler stub source generated from a class file  
// Implementation of methods is not available

package java.util;

public class ArrayList <E>  extends java.util.AbstractList<E>
implements java.util.List<E>, java.util.RandomAccess,
java.lang.Cloneable, java.io.Serializable {

private static final long serialVersionUID = 8683452581122892189L;
private static final int DEFAULT_CAPACITY = 10;
private static final java.lang.Object[] EMPTY_ELEMENTDATA;
private transient java.lang.Object[] elementData;
private int size;
private static final int MAX_ARRAY_SIZE = 2147483639;

public ArrayList(int i) { /* compiled code */ }

public ArrayList() { /* compiled code */ }

public ArrayList(java.util.Collection<? extends E> es) { /* compiled code */ }

However I seen it on other computer and it actually shows the Java source, not just a comment saying "compiled code".

How do I get this on my computer. Have I set up Java incorrectly?

like image 791
Yahya Uddin Avatar asked Feb 13 '23 09:02

Yahya Uddin


2 Answers

You should be able to configure it in your project structure (ctrl + alt + shift + S) settings here:

enter image description here

Is your JDK pointing to an invalid Sourcepath?

like image 167
Daniel Kaplan Avatar answered Feb 16 '23 04:02

Daniel Kaplan


I'm on Ubuntu 16.04 and OpenJDK 8. To get the JDK sources I had to separately install an additional package:

sudo apt-get install openjdk-8-source

Thanks to https://askubuntu.com/questions/755853/how-to-install-jdk-sources for the solution.

like image 45
Stanislav Karakhanov Avatar answered Feb 16 '23 04:02

Stanislav Karakhanov