Java source file displaying in IntelliJ as an empty decompiled class file

Brandon Essler :

I have a project with several .java files that I can view the source of perfectly in IntelliJ, except for one.

That file is a .java file like the others, but IntelliJ labels it a "Decompiled .class file" and the source is completely empty. If I open the file in a text editor, I can see the source just fine. Ant builds also work fine with this file.

These are not JDK sources that are missing, where you might expect to see decompiled code. And this is not a compiled .class file I'm opening, either.

Deleting the file from the project and updating from source control to restore it doesn't seem to help.

Here is what it looks like when I try to open the file in IntelliJ:

IntelliJ <code>.java</code> file as Decompiled <code>.class</code> file

What might cause this behavior in IntelliJ and what can I do to fix it?

Brandon Essler :

I did end up solving my issue.

Somehow, I inadvertently added that individual file's name to the Java Class File Types list, and so that file was associated as a decompiled .class files in the same way an actual .class file is.

The fix is going to Settings (Ctrl+Alt+S)EditorFile Types, scrolling down to Java Class in the list of Recognized File Types, selecting the file name in the list of Registered Patterns, and clicking the Remove button.

Settings, Editor, File Types Menu

I did not figure out how it was automatically added to that list. One guess is that I may have accepted a suggestion pop-up or selected the wrong Intention Action, and so the name of the open or active file was added to the .class type list.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=102422&siteId=1