IntelliJ shows decompiled .class file instead of source code - intellij-idea

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:
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:
Bytecode Viewer plugin is off.
Java Bytecode Decompiler plugin is off.
Platform, Project and Module all have same JDK version setup.
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
src.zip is not corrupt - I can open it via WinRAR
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.
Tried File > Invalidate Caches / Restart... - same result.
Same issue in 2017.3 and fresh 2018.1 versions of IntelliJ.
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.
Everything else works/compiles properly.
My settings:

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:
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.

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.

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.

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

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

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.

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.

On my Windows 10, expand maven:

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

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

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

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

This did the trick for me:
Make sure you select the option "Project Files" (instead e.g. "Project").

Related

Neo4J Plug In Won't Compile Due to Version Mismatch

I have seen variants of this question asked, but I have not seen an answer that was accepted. I am using IntelliJ IDEA to simply compile the TraversDemo sample plug in that Neo4J posted on GitHub. When I run mvn clean package I get no errors. But when I actually tried putting the .jar file into my plug ins folder on Neo4J Desktop . . . neo4j didn't recognize the plug in. So, I assumed something was wrong with my .jar file and I just tried to 'build' the java file in IntelliJ. When I did, I get this error:
Module 'TraversalPlugIn' production: java.lang.UnsupportedClassVersionError: org/neo4j/annotations/api/PublicApiAnnotationProcessor has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 54.0
I have checked and rechecked my Java (for Windows 10) is Java 8. I checked the Java Configuration GUI and asked for updates. It said I had the most recent version. Does anyone have any idea how to solve this? I already tried screwing around with various options in Build,Execution,Deployment Java compiler. No combination seemed to work.
I finally fixed this. The solution was: (i) cut existing java code (and POM file); (ii) delete original project altogether; (iii) create a new maven project but choose JDK 16 as SDK this time; and (iv) paste Java code and POM xml into new project. Then I built it, and ran maven clean package, inserted the target snapshot into the plug ins folder and ... it finally worked.

IntelliJ can't detect openjdk source, even though it's listed in project sources [duplicate]

How can I step through JDK source code in IntelliJ IDEA 7 and see the debug info? I can currently hit breakpoints and step through the code, but the debug info is not available. This means I can't see the value of local variables.
I only want to step through the source code of one class, if that matters.
For what it's worth, it's the javax.swing.text.html.HTMLDocument class and I do have a copy of the corresponding .java file.
If you look in [File menu ->] Settings -> Debugger -> Stepping you will see a list "Do not step into these classes", probably with "java.*" listed there. Is that the case? You can turn that off there.
Apparently the debug information is not available. According to this thread:
Sadly the JDK classes have debug information for parameters and local variable stripped off.
Years ago I filed a request that Idea should deduce the necessary information from the source code (basically converting variable names to indexes into the methods local var):
Debugger: Show variable information when no debug info
Please vote/comment.
As a workaround you can re-compile the JDK from sources, but you need to exclude some classes which do not have all needed source code attached.
Interestingly, you can download the beta version of Java 6u18, which has debug information in it (in the DEBUG bundle).
UPDATE: IntelliJ IDEA 13+ version can provide local variables information without debug info.
Java classes which are part of the JDK are compiled without debug info for the size and performance reasons. If you want debug info in these classes, you'll either need to install a development version of the JDK where the classes are built with the debug info or rebuild the parts of JDK you want to debug from source with the debug info enabled and configure the new JDK with these versions of classes in jars.
This thread provides the instructions how to rebuild JDK classes in rt.jar from the source code with debugging information.
P.S. This question is not specific to IntelliJ IDEA.
Install the JDK
OSX download: https://developer.apple.com/downloads
Windows download: http://www.oracle.com/technetwork/java/javase/downloads
Add src.jar path
Go to: Project Structure (Project Settings) > Platform Settings > SDKs > Sourcepath
Add the path to src.jar
OSX example: /Library/Java/JavaVirtualMachines/1.6.0_45-b06-451.jdk/Contents/Home
Windows example: C:\Program Files\Java\jdk1.7.0_03 (check Program (x86) for 32-bit)
Wait a long time for indexing!
Remove debugger filter
Go to: Settings > Debugger > Stepping
Uncheck the package(s) you want, e.g. javax.*
Along with the "Do not step into these classes" information, the src.jar should be configured. Right-click the project, select "Open Module Settings." Under Platform Settings, select "SDKs." Select the Java SDK version you're using. Select the Sourcepath tab, hit the "+" button, and add your src.jar from the JDK (or the separate source download for the OSX JDK). This will let you open JDK classes and step into them while debugging.
I did this on my Mac to get my Android source code but a similar approach should work for you.
File > Project Structure
Selected "SDKs" under Platform Settings.
Selected "Android SDK"
Selected "Sourcepath" tab
Pressed "+"
Browsed to location of my Java source code
you can find the source code from External Libraries --> rt.jar
setting - compiler - java Compiler - java options, you should check the option "generate debugging info", then, it will compile with debug info.

intellij - java: Cannot find JDK '1.7' for module

I've just installed IntelliJ on Windows 8 (and 7). I then use the 'Java Hello World' Sample as my project.
I then selected the JDK that was installed (C:\Program Files\Java\jdk1.7.0_10). Project creates successfully and I can see all the classes associated with the project etc. When I "make the project" I get the following error:
Compilation completed with 1 error and 0 warnings in 2 sec
1 error
0 warnings
java: Cannot find JDK '1.7' for module 'TEST'
No matter what I do I cannot compile any Java code under Windows8/IntelliJ
I have tried the following:
Invalidating cache.
Switching to 32bit JDK instead of 64bit
Idea64.exe instead of idea.exe
Installing 1.6 incase it was a 1.7 issue??
Changed the JAVA_HOME to point to different versions (ie currently C:\Program Files\Java\jdk1.7.0_10)
I'm lost as to why this is happening.
project structure > project > choose correct jdk
or ctrl+alt+shift+s > project> choose correct jdk
also platform settings > SDK's >and make sure 1.7 is there.
Found the root of the problem. Turns out Windows 8 under parallels shares the same Desktop as OSX. This confused IntelliJ somehow and as a result it couldn't compile properly.
In parallels by removing the "Desktop" shared under Configure this then resolves the issue.
In case you want to still share the documents & desktop, the solution is to modify the idea.properties file (for instance, under C:\Program Files (x86)\JetBrains\IntelliJ IDEA 12.1\bin\idea.properties ), and change the following properties to point to different a location that is specific to the OS in which you are working:
idea.config.path=
idea.system.path=
idea.plugins.path=
idea.log.path=
I also copied the previous folder (on my computer it was under
\\psf\Home\.IntelliJIdea12
) to the new location to preserve all settings.
Update: I had the same problem after I installed IntelliJ Idea 13. I moved the .IntelliJIdea13 folder to c:\Users\costa from \\psf\Home, then I modified the C:\Program Files (x86)\JetBrains\IntelliJ IDEA 13.0\bin\idea.properties file:
idea.config.path=C:/Users/costa/.IntelliJIdea13/config
idea.system.path=C:/Users/costa/.IntelliJIdea13/system
idea.plugins.path=C:/Users/costa/.IntelliJIdea13/config/plugins
idea.log.path=C:/Users/costa/.IntelliJIdea13/system/log
I made the error while editing idea.properties to leave a whitespace at the end of my personally added idea.config.path=../.IdeaIC/config line.
This resulted exactly in the Cannot find JDK '...' for module error message.
I needed to "trim" the line manually, just deleted the whitespace, restarted IntelliJ and everything worked fine again.
I found this while scanning the idea.log file where I found java.io.FileNotFoundException: C:\Software\IntelliJ IDEA Community Edition 14.1.3\.IdeaIC\config \tasks\root.contexts.zip
In my case, Idea said "Failed to save settings" (probably due to a lot of projects being open. After that, it could not run tests with "Cannot find JDK '1.8' for module XXX" message. Idea restart solved the issue for me.
I believe this is an IntelliJ bug.
This isn't a fix, but you can work around this by going to Settings > Compiler, and disabling 'Use External Build'.
It seems that sometimes Intellij (or the user:-)) is getting confused when importing settings, especially if you change the paths where the jdk resides (for me it happened during a migration to a new Linux environment).
The only way I could correct this was to delete the user's settings folder.
In Linux :
I removed the folder (and subfolders): ~/.IntelliJIdea12/
Of course this would remove the saved settings, licenses e.t.c.

JavaFX source code not showing

I downloaded the JavaFx source code from http://hg.openjdk.java.net/openjfx/2.2/master/rt/summary.
The name of the folder in the zip file is re-e71070b0e0c0.
I unzipped this and added the folder under Project Structure - Global Libraries in Idea, however it doesn't work. When I try to open a class it just shows field names and /* compiled code */. I couldn't find anything in the manual.
Much of the information in this answer is now outdated.
More up-to-date information on using JavaFX with Java 11+ in IntelliJ Idea, is available at:
openjfx.io in the section titled: "JavaFX and IntelliJ".
Though, the above-linked article is more focused on using JavaFX in IntelliJ rather than viewing JavaFX library source code in IntelliJ.
These instructions are only necessary for the JavaFX 2.x branch and will be obsoleted once JDK 8 is released.
After you have downloaded the source zip and extracted it, open Idea and follow these instructions:
Modify the source structure for your 1.7 SDK:
File | Project Structure | SDKs | Sourcepath
For each sub-project in the extracted zip, type Alt+Insert and add the respective source directory. For example rt-e71070b0e0c0\javafx-ui-charts\src, rt-e71070b0e0c0\javafx-ui-common\src, etc. Not all JavaFX 2.x source code is currently open sourced, so this will only add the open sourced portions.
Set the documentation lookup path:
File | Project Structure | SDKs | Documentation Paths
Specify a url Alt+S for the documentation: http://docs.oracle.com/javafx/2/api/
In your JavaFX application source, place your cursor over a JavaFX class usage, for instance LineChart:
Press Ctrl+B to open the source code file LineChart.java from your downloaded zip.
Press Shift+F1 to open documentation on the LineChart in a browser.
Press Ctrl+Q to get quick access to documentation from in the IDE.
Update Oct 16 2013
JDK 8 now includes JavaFX source files.
To tell Idea where JavaFX sources are:
Modify the source structure for your 1.8 SDK:
File | Project Structure | SDKs | Sourcepath
Press Alt+S to add the file javafx-src.zip, which is located in the root directory of the JDK 8 distribution.
Set the documentation lookup path:
File | Project Structure | SDKs | Documentation Paths
Specify a url Alt+S for the documentation: http://download.java.net/jdk8/jfxdocs.
The JDK 8 JavaFX documentation url will likely change when JDK 8 reaches General Availability release stage.
Step 3 above provides keyboard shortcuts to quickly access the JavaFX sources and documentation from your project.
(Since this is one of the Google hits for "javafx source code", I'll dump this anwer here too):
Quoting from this answer: For Java 8, the source of the public parts of JavaFX are actually laying right along in the JDK installation as a sibling of src.zip: javafx-src.zip - on the root of your normal JDK Java 8 installation.
Eclipse doesn't by default link them up when you add the JRE (or it finds it itself) - obviously a bug - so you'll have to do that yourself, by hitting Preferences -> Installed JREs. Find your JDK 8, hit Edit button. On the list JRE system libraries, expand the jfxrt.jar node, and link in the javafx-src.zip file.
I've faced this problem on Ubuntu 16.04 with JavaFX 8 (open-jfx package). The fix was to install the missing source package:
sudo apt install openjfx-source
IntellJ started showing JavaFX source code the second after the command finished executing.

How to view JDK external documentation in IntelliJ IDEA?

The shortcut for this action is Shift+F1 but it is always grayed out even though I have pointed JDK documentation path to the docs folder (the docs folder is unzipped from jdk-7u2-apidocs.zip ).
Thanks
You need to specify the docs/api subdirectory of the unpacked documentation or use https://docs.oracle.com/javase/8/docs/api/ URL for the external documentation feature to work.
File -> Project Structure... then here :
I'm using 10.5.4. It was unclear to me from the docs or from resources online that you need to add this at Project Structure > SDK's > (Choose your SDK) > Documentation Paths > Specify URL.
For IntelliJ Idea:
Call "Project Structure" (Ctrl+Shift+Alt+S), go to "Platform Setting - SDKs", choose "Documentation Path" tab on the right, then add url of JavaDoc (http://docs.oracle.com/javase/7/docs/api/) to your project
You can add the external Javadocs API link as shown below:
Go to File > Project Structure...
Then select SDKs (under Platform Settings)
Go to Documentation Paths tab
Select Specify URL button and add the link for JDK 11 API docs (https://docs.oracle.com/en/java/javase/11/docs/api/)
I understand the question as follows:
You would like to see javadocs of classes that are not within JDK. I am a bit uncertain because CrazyCoder's reply is talking about JDK specific javadocs.
I am using Macos 10.8.4 and Intellij 11.1.5
The project I am working on is a mvn based project with many modules which have complex dependencies.
Let me take a concrete example to explain what I did, I am sure it can be reproduced for others: apache sshd
I downloaded the javadoc from maven central stored it stored it somewhere. In intellij I went to the module settings (shortcut F4) and the to Libraries in the sidebar. Maven pulls all dependencies automagically and I can find sshd there. The right side then shows Classes, Sources and JavaDocs. The JavaDocs part in my case had a path linked in that pointed to my local m2 directory. However the directory did not contain the javadoc jar file. So I thought how do I get it:
mvn dependency:resolve -Dclassifier=javadoc
Taken from here
However this failed for because we do not have some javadocs in our nexus (I guess, not sure).
So I ended up linking the file that I downloaded manually in as a javadoc link and this then allown me to use Shift+F1 for the javadoc to open in my standard browser.
Maybe others can elaborate on how to get this done with mvn. I did not have the time to further investigate.
Posting this here in case you're like me and don't necessarily want javadocs, but rather the documentation inside your IDE.
In my situation, I had downloaded OpenJDK 11 and wasn't able to get documentation inside IntelliJ. Instead I was getting decompiled code.
What helped me was the answer at https://stackoverflow.com/a/38413439
i.e.
Go to File > Project Structure > SDKs > Sourcepath > '+' on the right side.
Navigate to your JDK (I'm on Ubuntu so it was located under /usr/lib/jvm/openjdk-11/).
Select the src.zip (for me, /usr/lib/jvm/openjdk-11/lib/src.zip).
Click OK > OK (to "Choose Roots" pop-up) > OK (to Project Structure)
Let Intellij index and it should be available in your IDE.
Java 10 Documentation path
Got to File -> Project Structure Choose External URL
Below Link works Fine... THe default one does'nt work
https://docs.oracle.com/javase/10/docs/api/
Other answers are satisfying but in case you still can't see the documentation, make sure that your java file is located under the src path.