aspose file tools*
The moose likes Java in General and the fly likes Decompile class files of Java 1.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Decompile class files of Java 1.5 " Watch "Decompile class files of Java 1.5 " New topic
Author

Decompile class files of Java 1.5

Uday Shankar Mareedu
Greenhorn

Joined: Jun 30, 2012
Posts: 3
Hi,

In my project I had a jar file, now I need to change the code in one of the class in that jar.
I don't have source code version of that jar, was compiled using java 1.5 which uses generics as well.
I need to decompile, recompile and place the new class in that jar, will it work?

Please suggest me the best decompiler which decompiles java 1.5 class files.

Any help would be highly appreciate.


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Welcome to the Ranch!

I hate to say it, but when you decompile a class file you're not going to get the exact source file. Comments don't exist in class files. Parameter and local variable names are not stored in class files. And worst of all, because of type erasure, generic information does not exist in class files.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42278
    
  64
Most of the better-known decompilers (like JODE and jad) weren't updated to handle generics. JD-GUI handles them to some degree, but not perfectly. Just give it a try, YMMV.

Rob Spoor wrote:And worst of all, because of type erasure, generic information does not exist in class files.

Not quite - the information is in the class file, it's just not used at runtime by the JVM. But a decompiler can get at that information.


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Really? Interesting. I guess the JAD version I'm using is too outdated then.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42278
    
  64
Yep, jad was never updated to deal with generics. JODE wasn't either (publicly), but I was successful in enhancing it to make use of a fair amount of the available information to create source files that have more of the Java 5 stuff.
Uday Shankar Mareedu
Greenhorn

Joined: Jun 30, 2012
Posts: 3
I had tried with JD-GUI, JAD, DJ but no luck.
I am getting exception hierarchy errors and type cast errors for collections.

Please help me out to resolve this, it is very important for me to move further.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Before you continue, are you sure you're even allowed to modify the classes inside the JAR file? If it's a third party library JAR file and it's been released under some non open source license, decompiling the classes and modifying their contents may be illegal. If it's a JAR file created by the company you work for, the code should still be available. Of course it doesn't have to be unfortunately...
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Uday Shankar Mareedu wrote:I had tried with JD-GUI, JAD, DJ but no luck.
I am getting exception hierarchy errors and type cast errors for collections.

Please help me out to resolve this, it is very important for me to move further.

First: EaseUp (←click). We're volunteers here.

Second: Further to what Rob said, even if you are allowed to do it, I'd be very leery of any "solution" based on a decompilation. Reverse-engineering is tricky stuff. I hope you've run it by your boss AND told him about all the possible downsides.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Decompile class files of Java 1.5