Storyyeller / Krakatau

Java decompiler, assembler, and disassembler
GNU General Public License v3.0
1.97k stars 220 forks source link

Exceptions throwing declarations #122

Closed lab313ru closed 6 years ago

lab313ru commented 6 years ago

For example, method throws an exception. So, in declaration it should be 'throws bla.bla.bla'. But there is no such output.

Storyyeller commented 6 years ago

Unfortunately, this is one of many features in Java that is impossible to decompile in general. The problem is that there are no checked exceptions at the bytecode level, so it's not clear how to handle the throws declarations required at the Java language level. One possibility is to put "throws Throwable" on every method, but that adds noise and it still doesn't compile because the compiler will complain that you aren't catching Throwable everywhere. Therefore, I decided that it was best to not try generating throws declarations at all.

lab313ru commented 6 years ago

Some decompilers are doing that somehow. I think, for example enumerating all throwable exception in current method.

Storyyeller commented 6 years ago

They could just be using the Exceptions attribute. But Krakatau is designed to handle arbitrary bytecode, not just bytecode produced directly by Javac, so it tries to avoid relying on metadata that has no effect on execution.

I guess the question is what advantage you expect to get from decompiling the Exceptions attribute. My assumption is that it would be stripped or faked in obfuscated code anyway, so there's little point in writing a bunch of special code to decompile it.

lab313ru commented 6 years ago

Can you add some switch for that? Because if I have many methods that are throwing exceptions it becomes a hell to reconstruct the code!

Storyyeller commented 6 years ago

What exactly are you trying to accomplish?

lab313ru commented 6 years ago

Reconstruct the code with less efforts.:)

Storyyeller commented 6 years ago

What do you mean by "reconstruct the code"?

lab313ru commented 6 years ago

I have a jar file (bunch of class files), and I want to restore the code from which it was compiled. But for now I don't have that code, only jar file.

Storyyeller commented 6 years ago

Why do you want to do that?

lab313ru commented 6 years ago

One stupid mistake in my program makes me angry every time when it happens, so I want to fix it. And I found such excellent project as Krakatau.

Storyyeller commented 6 years ago

Sorry, I still don't understand what you are trying to accomplish. Could you explain please?

lab313ru commented 6 years ago

Sure.

Look, I have a big jar file of my program, which sources I've lost. There are many methods that are throwing exceptions. But after decompilation source code doesn't have 'throws blabla' in class methods definitions. Sure, I can add it manually in every case, but there are so many such methods that it will become a hell to fix all of that. So, I want ask you to add this feature to decompiler: restoring exceptions info.

skochinsky commented 6 years ago

Does the program not work without throw declarations?

lab313ru commented 6 years ago

IntelliJ IDEA doesn't want to compile the source code.

Storyyeller commented 6 years ago

If your goal is to get back nice editable source code because you lost your source, I would recommend using a different decompiler. That's not what the Krakatau decompiler was designed to do. Of course, you'll still have to do some manual editing no matter which tool you use, and there's no way to ever recover comments or formatting.

lab313ru commented 6 years ago

I have to agree with that.:)