Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Decompile class files of Java 1.5

 
Uday Shankar Mareedu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really? Interesting. I guess the JAD version I'm using is too outdated then.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10232
58
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic