-1

Enhanced Class Decompiler is installed still I am unable to decompile .class to .java source?

enter image description here

I am trying to decompile java core class - Collections.class - Could some one guide me how to get past this.

enter image description here

I am using STS 4.8.x
enter image description here

  • 2
    The [embedded JDK that is used to run Eclipse/STS4 does not contain the sources](https://twitter.com/martinlippert/status/1313820812294713345). Make sure a Java JDK is installed in your system (if missing, you can download Java e.g. from [AdoptOpenJDK](https://adoptopenjdk.net/)) and configure it in the preferences in _Java > Installed JREs_. Do not use this decompiler hack since you also want to have the Javadoc. – howlger Oct 13 '20 at 12:24
  • The source code that comes with a Java JDK includes all the comments and Javadoc that will be missing if you use a decompiler. – greg-449 Oct 13 '20 at 12:37
  • @greg-449 and howlger - - tx. I want to use the sources later, for now I want to go with the decompiler just for a short while –  Oct 13 '20 at 12:42
  • greg-449 and @howlger -spring classes are decompiling with out issue...how is this possible. –  Oct 13 '20 at 12:43
  • @howlger -spring classes are decompiling with out issue thats fine... but i am seeing javadoc too... how is this possible –  Oct 13 '20 at 13:47
  • 1
    @RedwinD Bytecode cannot contain Javadoc comments and therefore it is not possible that Javadoc is in a decompiled class. Probably, you look at the real source code, not at a decompiled class. Fix the root problem instead of wasting time with the decompiler hack. – howlger Oct 13 '20 at 13:53
  • @howlger, i uninstalled the decompiler, still spring classes can be decompiled to sources, how is this possible... how can sts provide such feature... my pom has no sources mentioned. –  Oct 13 '20 at 14:00
  • @RedwinD It's done by the Maven integration: in the preferences _Maven_ there is the option _Download Artifact Sources_ which is enabled by default. – howlger Oct 13 '20 at 14:30
  • @howlger, gr8 and tx. found one `spring-security-core-5.2.2.RELEASE-sources.jar` and the preference is set to download sources. –  Oct 13 '20 at 14:58
  • @howlger, so sad, by-default one is able to get third party sources to debug/read but not java sources :-(( –  Oct 13 '20 at 15:00
  • @RedwinD You just have to do what I said in the first comment. You have to do this only once and it will not take much longer than it took you to install the decompiler. – howlger Oct 13 '20 at 15:37
  • @howlger, appreciate your emphasis. Added the installed JDK to STS. And ended up with `The JAR file /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar has no source attachement`. so now going after it. [openjdk-8-jdk - missing src.zip?](https://stackoverflow.com/questions/64340084/openjdk-8-jdk-missing-src-zip) –  Oct 13 '20 at 17:50
  • @RedwinD Now you have a JRE (`.../jre/...`) instead of JDK. A JRE has no sources. Go for a JDK instead of adding sources to the JRE. – howlger Oct 13 '20 at 21:40
  • @howlger - You should write an answer. – Stephen C Oct 14 '20 at 00:22
  • @howlger - this helped [openjdk-8-jdk - missing src.zip?](https://stackoverflow.com/questions/64340084/openjdk-8-jdk-missing-src-zip). Bye-the-way, i will be more than happy to accept if you write down an answer. :-) –  Oct 16 '20 at 13:28

1 Answers1

1

The root cause is that the JDK embedded in the Spring Tools 4 does not contain sources. That the Spring Tools 4 application is shipped with an embedded JDK (from Eclipse JustJ) is currently a new feature, but the missing sources is an issue that will probably be fixed in an upcoming release (according to this tweet by the STS4 main developer).

As solution (and workaround for the missing sources of the embedded JDK), make sure a JDK (not a JRE) is installed in your system (if missing, you can download a JDK e.g. from AdoptOpenJDK) and configure it in the preferences in Java > Installed JREs.

Using the decompiler hack has the disadvantage that the Javadoc will be missing.

howlger
  • 31,050
  • 11
  • 59
  • 99