56

I am having issues with IntelliJ - it shows me a "decompiled" version of the class instead of its source code if I ctrl+click the class.

This is what I see:

Decompiled class message

I am trying to open regular JDK source files.

The most relevant issue I found is explained here: Java sources replaced by decompiled files in Intellij

The most detailed answer I've found so far is there as well.

Yet it doesn't work for me:

  1. Bytecode Viewer plugin is off.

  2. Java Bytecode Decompiler plugin is off.

  3. Platform, Project and Module all have same JDK version setup.

  4. I have two JDKs available in IntelliJ: jdk1.8.0_161 and jbsdk8u112b287.2_windows_x86 (bundled with IntelliJ, but comes without src.zip). Tried with both (had to specify src.zip of jdk1.8.0_161 for jbsdk8u112b287.2_windows_x86) - no luck

  5. src.zip is not corrupt - I can open it via WinRAR

  6. When added jdk1.8.0_161 to IntelliJ, it automatically found src.zip. When manually adding src.zip to jbsdk8u112b287.2_windows_x86 Sourcepath tab - it started "Scanning for roots", but warned me that it "cannot determine what kind of files the chosen items contain" and offered me to "attach them as 'Sources'" so I agreed.

  7. Tried File > Invalidate Caches / Restart... - same result.

  8. Same issue in 2017.3 and fresh 2018.1 versions of IntelliJ.

  9. Providing path for Documentation makes IntelliJ look for the documentation in the path specified. So it works as it should for both of JDKs. But not for sources.

  10. Everything else works/compiles properly.

My settings:

Settings

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
takeoff
  • 573
  • 1
  • 4
  • 6
  • Which of the 2 configured JDKs is used in the project/modules? Does it have the sources attached? Try removing the second JDK configuration. – CrazyCoder Mar 29 '18 at 19:15
  • Thanks for reply. I tried both jdks while being consistent with them in project/module with no luck. Just deleted bundled jdk, invalidated cache, restarted. The issue is still there. Now I have 2 machines to compare. Both have same new IDE version. Both run 32-bit version of Intellij. Both have same and only version of jdk installed (jdk1.8.0_161). Both have same settings (synced via settings repository). And on the 2nd machine everything works as it should! Same behavior when creating new project. I don't even know what to try now... – takeoff Mar 29 '18 at 20:56
  • 1
    Try to delete IDE configuration (https://intellij-support.jetbrains.com/hc/articles/206544519), then set up everything from scratch without importing the settings. – CrazyCoder Mar 29 '18 at 21:21
  • 2
    ok, it looks like the problem is in the project itself. Removing settings fixes the issue, until I open the project. Then I get this decompiling message asking to agree to some conditions and then it starts showing me a decompiled code version once again. Had to re-import it instead of re-open – takeoff Mar 30 '18 at 21:33
  • unfortunately, it still happens from time to time. Now in my project in Android Studio.. to lazy to fight it back.. Try settings removal and re-importing your project as mentioned above – takeoff Jun 28 '18 at 18:55
  • Did somebody figure out which config setting exactly is the issue? Wanna avoid having to set up everything from scratch... – Clauds Jan 23 '19 at 14:17

13 Answers13

25

1. Get the source files

Make sure you have downloaded and installed the source files of the JDK.

I'm on Arch Linux and installed them with pacman -S openjdk8-src which put a src.zip into /usr/lib/jvm/java-8-openjdk/. We'll use that zip file in the next step.

To list source packages of different JDK versions, do pacman -Ss "openjdk.*-src".

See this question on how to get the source files for your specific platform.

2. Point IntelliJ to the source files

In your module settings (open them with F4) under "Platform Settings" → "SDKs" → "Sourcepath", add the zip file containing the JDK source to your project JDK (be sure to pick the right JDK if IntelliJ lists more than one JDK) using the button with the plus sign:

Sourcepath screenshot

3. Jump into the source

Select a JDK class, like Comparator, using IntelliJ's Search Everywhere or Ctrl+b with the cursor on the name of the class.

Comparator source

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
  • I've tried this and it is impossible for me to select and add the src.zip file even though it is there in the file system. IntelliJ does not show it in the file list, and if I manually type "src.zip" at the end of the path then IntelliJ automatically erases it from the text input field after about 0.5 seconds! – flodin May 15 '23 at 09:12
  • 1
    @flodin: Could it be that IntelliJ doesn't have the permission to access the file or its directory? Maybe try changing the permissions with `chmod` (assuming you use macOS or Linux) or save the src.zip somewhere else. – Matthias Braun May 15 '23 at 10:28
  • Good thinking. It wasn't a permissions issue. It turns out that the src.zip file is in fact a symbolic link, and it points to a path that doesn't exist. This is on a stock install of openjdk from the Ubuntu package repository so it seems like a distribution bug. – flodin May 16 '23 at 11:12
  • 1
    Update: Installing openjdk-VERSION-source made the symlink resolve and now it works fine. Confusing behavior from both IntelliJ and Ubuntu conspired to make this hard to crack. – flodin May 16 '23 at 11:24
3

I also have the same problem. The problem for my case is that Project SDK is set to 13 [Invalid]. After I can Project SDK to a valid SDK. My problem is solved.

Project Structure

Jingguo Yao
  • 7,320
  • 6
  • 50
  • 63
1

I tried all the things mentioned at other places for this but at the end I was doing a silly mistake. Intellij was pointing to JDK 11 for which there was no source code (I had both the SDKs 8 & 11). I removed JDK 11 and pointed to JDK 8. JDK had the source code, thus now I can see the source code on ctrl click. Also, I had disabled the bytecode viewer and decompiler plugins. Hope this helps some one.

  • Disabling the bytecode viewer and decompiler plugins did the trick for me as I had tried everything else. Thank you! – Christoph Sep 22 '21 at 12:10
1

This also happens for large files - IDEA decides to decompile them instead if indexing sources, which can take ages. If you're willing to accept the drawdown, adding the following in Help | Edit Custom Properties might fix the problem:

idea.max.intellisense.filesize=4096
miracle_the_V
  • 1,006
  • 1
  • 14
  • 31
1

On my Windows 10, expand maven:

enter image description here

1

On ubuntu there was java version “OpenJDK” when I changed to “Oracle Java”, the error went away and javadoc returned

0

I meet same problem and finally it gone after I copy JDK to another folder and change config in IntelliJ. I think maybe cause there is a space in path before, because it is installed under "Program Files" folder.

Xilang
  • 1,513
  • 3
  • 18
  • 36
0

For downloading the source code of class files belong to jar you can use download source option present on top right corner in the de-compiled class file.

enter image description here

Raunak Kapoor
  • 731
  • 6
  • 14
  • In my experience, this does not work for JDKs, only things like maven dependencies. And, for those, specifically, you can setup IntelliJ to always download maven sources. – Derek White Nov 24 '21 at 00:25
0

For me going to File -> Project Structure -> Project -> SDK -> Add SDK -> Download JDK and selecting Oracle OpenJDK solved the problem. Prior to that I had a different JDK selected and apparently it didn't include source code

konnovdev
  • 823
  • 8
  • 16
-1

If you are in a maven project make sure in the project structure all the complied folders are in the excluded section. enter image description here

-1
  1. I suggest to use Linux Instead of windows. It's easy to find and download Java.
  2. If you are using Linux, you can download SDKMAN
  3. Install Java by SDKMAN
# find version
$ sdk list java
# download
$ sdk install java x.y.z-amzn
  1. ctrl+alt+shift+s add JDK enter image description here

  2. Switch project JDK enter image description here

Jess Chen
  • 3,136
  • 1
  • 26
  • 35
-1

If you are using maven , Right click on Project explorer -> choose Maven -> chick on "reload projects"

Syed Irfan
  • 179
  • 1
  • 1
  • 6
-2

This did the trick for me:

Make sure you select the option "Project Files" (instead e.g. "Project").

screenshot

wibeasley
  • 5,000
  • 3
  • 34
  • 62