2

I'm trying to load the code in UnixFileSystemProvider so I can debug through it. IntelliJ generates a source stub but can't find the library.

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

This is confusing to me because I know from grepcode that it lives in openjdk, which presumably since I am running I have the source access to.

I used findjar.com, a pretty good resource that I would expect to have any basic resource, to do a search for it and hopefully find it in a Maven repo or something, but nothing came up.

How do I make my IDE aware of this source, either by getting a jar myself, giving it Maven coordinates or otherwise?

durron597
  • 31,968
  • 17
  • 99
  • 158
djechlin
  • 59,258
  • 35
  • 162
  • 290

2 Answers2

0

Here's a thread which should answer getting the source code: Where to find Java JDK Source Code?

In my version of intellij, I have added the jdk source by defining a jvm/jdk and then in "project structure" -> "sourcepath" tab I pointed it to the src.zip file that matches my java version.

jar:///Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/src.zip!/

To associate the source of a jar file, you can define a library as follows:

<component name="libraryTable">
  <library name="SBT: com.typesafe.play:play-datacommons_2.10:2.2.3">
    <CLASSES>
      <root url="jar://$USER_HOME$/.ivy2/cache/com.typesafe.play/play-datacommons_2.10/jars/play-datacommons_2.10-2.2.3.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES>
      <root url="jar://$USER_HOME$/.ivy2/cache/com.typesafe.play/play-datacommons_2.10/srcs/play-datacommons_2.10-2.2.3-sources.jar!/" />
    </SOURCES>
  </library>
</component>
Community
  • 1
  • 1
thebiggestlebowski
  • 2,610
  • 1
  • 33
  • 30
0

Before anything, two caveats: I'm going to assume you are debugging code from OpenJDK (which has the source code for sun.nio.fs.UnixFileSystemProvider), and the IntelliJ version I'm using is the Ultimate, I'm not sure if this also works in the community edition; if so, then let me know and I'll edit my answer.

You need to get the source code and then "attach" it for it to match the bytecode (so make sure the source code you get is the once corresponding to the compiled version)

1 - get the source code

For v6 and v7:

If you are using a debian-based Linux distribution it is preferable installing the sources from the deb repositories:

sudo apt-get install openjdk-7-source

Or using aptitude:

aptitude install openjdk-7-source

The source code will be located in /usr/lib/jvm/java-version/src.zip

Alternatively there is a version of OpenJDK 7 available for download here: http://download.java.net/openjdk/jdk7/

For v6: http://download.java.net/openjdk/jdk6/

If you are using OpenJDK v8 then the process to download the source code gets a little bit more complicated, it involves cloning repositories from the OpenJDK's website using mercurial (and it would be too long to explain how to use mercurial here, so I hope you're using v6 or v7)

2 - Attaching the source code to your binaries

when you get the decompiler stub from IntelliJ, click on "Attach Sources...":

IDE location to attach sources

Then browse to the location (directory or zip file) where the source code is and select it:

enter image description here

If everything was Ok you should be able to browse through the source code now.

morgano
  • 17,210
  • 10
  • 45
  • 56