• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Decompile class files of Java 1.5

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Really? Interesting. I guess the JAD version I'm using is too outdated then.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic