Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IDEA 14. Decompile my own classes(from output directory)

I want to look at the code generated from my own sources but it seems that IDEA doesn't decompile them using new fernflower plugin using IntelliJ API Decompiler instead.

At least I have header comment

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

and methods like that: public void update() { /* compiled code */ }

At the same time, in external library(for example JDK), i see normal header and decompiled code.

// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)

I can make decompiler works, if I compile code to jar and add it to some module, but it's doesn't look like a normal solution.

Can I make IDEA decompile any class file using fernflower?

EDIT: While opening file I get an exception in IDEA log file. See snippet.

<pre>
2015-02-13 19:16:29,991 [119281666]   WARN - l.compiled.ClassFileDecompiler - decompiler: class org.jetbrains.java.decompiler.IdeaDecompiler
com.intellij.psi.compiled.ClassFileDecompilers$Light$CannotDecompileException: org.jetbrains.java.decompiler.IdeaLogger$InternalException: Method <init> (Ljava/util/HashMap;)V couldn't be decompiled.
	at org.jetbrains.java.decompiler.IdeaDecompiler.getText(IdeaDecompiler.java:162)
	at com.intellij.psi.impl.compiled.ClassFileDecompiler.decompile(ClassFileDecompiler.java:57)
	at com.intellij.openapi.fileEditor.impl.LoadTextUtil.loadText(LoadTextUtil.java:364)
	at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.getDocument(FileDocumentManagerImpl.java:167)
	at com.intellij.openapi.fileEditor.impl.text.PsiAwareTextEditorProvider.createEditorAsync(PsiAwareTextEditorProvider.java:58)
	at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl4(FileEditorManagerImpl.java:778)
	at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl3(FileEditorManagerImpl.java:736)
	at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl$8.run(FileEditorManagerImpl.java:716)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:117)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:99)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:85)
	at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl2(FileEditorManagerImpl.java:713)
	at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileWithProviders(FileEditorManagerImpl.java:654)
	at com.intellij.openapi.fileEditor.ex.FileEditorManagerEx.openFile(FileEditorManagerEx.java:146)
	at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl$14.run(FileEditorManagerImpl.java:1071)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:124)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:99)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:85)
	at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openEditor(FileEditorManagerImpl.java:1067)
	at com.intellij.openapi.fileEditor.OpenFileDescriptor.navigateInAnyFileEditor(OpenFileDescriptor.java:152)
	at com.intellij.openapi.fileEditor.OpenFileDescriptor.navigateInEditor(OpenFileDescriptor.java:138)
	at com.intellij.openapi.fileEditor.OpenFileDescriptor.navigateInEditorOrNativeApp(OpenFileDescriptor.java:134)
	at com.intellij.openapi.fileEditor.OpenFileDescriptor.navigate(OpenFileDescriptor.java:121)
	at com.intellij.psi.impl.PsiElementBase.navigate(PsiElementBase.java:197)
	at com.intellij.codeInsight.navigation.NavigationUtil.openFileWithPsiElement(NavigationUtil.java:167)
	at com.intellij.ide.projectView.impl.nodes.AbstractPsiBasedNode.navigate(AbstractPsiBasedNode.java:207)
	at com.intellij.ide.projectView.impl.nodes.AbstractPsiBasedNode.navigate(AbstractPsiBasedNode.java:217)
	at com.intellij.ide.projectView.impl.nodes.PsiFileNode.navigate(PsiFileNode.java:132)
	at com.intellij.util.OpenSourceUtil.navigate(OpenSourceUtil.java:53)
	at com.intellij.util.OpenSourceUtil.openSourcesFrom(OpenSourceUtil.java:31)
	at com.intellij.util.EditSourceOnDoubleClickHandler$TreeMouseListener.processDoubleClick(EditSourceOnDoubleClickHandler.java:130)
	at com.intellij.util.EditSourceOnDoubleClickHandler$TreeMouseListener.onDoubleClick(EditSourceOnDoubleClickHandler.java:122)
	at com.intellij.ui.DoubleClickListener.onClick(DoubleClickListener.java:30)
	at com.intellij.ui.ClickListener$1.mouseReleased(ClickListener.java:73)
	at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:273)
	at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
	at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
	at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
	at java.awt.Component.processMouseEvent(Component.java:6414)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
	at com.intellij.ui.treeStructure.Tree.processMouseEvent(Tree.java:421)
	at com.intellij.ide.dnd.aware.DnDAwareTree.processMouseEvent(DnDAwareTree.java:53)
	at java.awt.Component.processEvent(Component.java:6179)
	at java.awt.Container.processEvent(Container.java:2084)
	at java.awt.Component.dispatchEventImpl(Component.java:4776)
	at java.awt.Container.dispatchEventImpl(Container.java:2142)
	at java.awt.Component.dispatchEvent(Component.java:4604)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4618)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4279)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4209)
	at java.awt.Container.dispatchEventImpl(Container.java:2128)
	at java.awt.Window.dispatchEventImpl(Window.java:2492)
	at java.awt.Component.dispatchEvent(Component.java:4604)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:717)
	at java.awt.EventQueue.access$400(EventQueue.java:82)
	at java.awt.EventQueue$2.run(EventQueue.java:676)
	at java.awt.EventQueue$2.run(EventQueue.java:674)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:690)
	at java.awt.EventQueue$3.run(EventQueue.java:688)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:687)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:748)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:573)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:384)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: org.jetbrains.java.decompiler.IdeaLogger$InternalException: Method <init> (Ljava/util/HashMap;)V couldn't be decompiled.
	at org.jetbrains.java.decompiler.IdeaLogger.writeMessage(IdeaLogger.java:44)
	at org.jetbrains.java.decompiler.main.rels.ClassWrapper.init(ClassWrapper.java:151)
	at org.jetbrains.java.decompiler.main.ClassesProcessor.initWrappers(ClassesProcessor.java:305)
	at org.jetbrains.java.decompiler.main.ClassesProcessor.writeClass(ClassesProcessor.java:252)
	at org.jetbrains.java.decompiler.main.Fernflower.getClassContent(Fernflower.java:86)
	at org.jetbrains.java.decompiler.struct.ContextUnit.save(ContextUnit.java:113)
	at org.jetbrains.java.decompiler.struct.StructContext.saveContext(StructContext.java:72)
	at org.jetbrains.java.decompiler.main.Fernflower.decompileContext(Fernflower.java:54)
	at org.jetbrains.java.decompiler.main.decompiler.BaseDecompiler.decompileContext(BaseDecompiler.java:41)
	at org.jetbrains.java.decompiler.IdeaDecompiler.getText(IdeaDecompiler.java:151)
	... 73 more
Caused by: java.lang.ClassCastException: org.jetbrains.java.decompiler.struct.consts.PrimitiveConstant cannot be cast to org.jetbrains.java.decompiler.struct.consts.LinkConstant
	at org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor.processBlock(ExprProcessor.java:563)
	at org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor.processStatement(ExprProcessor.java:202)
	at org.jetbrains.java.decompiler.main.rels.MethodProcessorThread.codeToJava(MethodProcessorThread.java:162)
	at org.jetbrains.java.decompiler.main.rels.ClassWrapper.init(ClassWrapper.java:92)
	... 81 more
</pre>
like image 640
Seagull Avatar asked Feb 09 '15 00:02

Seagull


People also ask

Can class files be decompiled?

In order to decompile class file, just open any of your Java projects and go to Maven dependencies of libraries to see the jar files included in your project. Just expand any jar file for which you don't have the source attached in Eclipse and click on the . class file.

Does IntelliJ have a decompiler?

IntelliJ IDEA features the Java bytecode decompiler that shows you compiled bytecode as if it were human-readable Java code. The decompiler is enabled by default. Open a compiled . class file in the editor.


1 Answers

In my case the problem was that I had installed "Java Decompiler IntelliJ Plugin". Unistall it makes the job.

like image 158
RoberMP Avatar answered Sep 20 '22 07:09

RoberMP