views:

326

answers:

4

I've been staring at this issue for hours now. Any help is appreciated.

I wrote code that uses the Jode decompiler from the "embedded jode jar file". I want to use this version because it is under the Lesser GNU Public License.

Decompiler d = new Decompiler();
try {
    FileWriter fw = new FileWriter("c:\\jode.txt");

    d.setClassPath("C:\\mycode");

    ProgressListener p = new ProgressListener() {

        public void updateProgress(double arg0, String arg1) {
            System.out.println("inside of progress listener with arg0 = " +arg0+ " and arg1 = " +arg1);
        }
    };

    d.decompile("Test.class" , fw, p);

} catch (Exception ex) {
    ex.printStackTrace();
}

and I always get :

Exception in thread "main" java.lang.NoClassDefFoundError: Test.class
        at jode.bytecode.ClassInfo.loadInfo(ClassInfo.java:620)
        at jode.decompiler.ClassAnalyzer.<init>(ClassAnalyzer.java:86)
        at jode.decompiler.ClassAnalyzer.<init>(ClassAnalyzer.java:123)
        at jode.decompiler.Decompiler.decompile(Decompiler.java:191)
        at testdecompiler.Main.main(Main.java:45)

If I use

jode.decompiler.Main.decompile(...)

things work - but I can't use this class file because it resides in the jode.jar that is only GPL.

A: 
d.setClassPath("C:\\mycode");

This classpath looks awfully short to me.

Vladimir Dyuzhev
Hi Vladimir, Yes, it's not the real value of the classpath, because I don't want to advertise it here. I basically set it to a string that points to the location of the class file being decompiled. Is that correct?
Amir Afghani
What I mean is that NoClassDefFound can be not the topmost one. If a class your class depends upon cannot be found, you can get NoClassDefFound despite your class IS in the classpath. Your classpath, I believe, should contain at least JRE rt.jar. Possibly, I'd took my own process classpath, appended your test dir (semicolon-separated, according to Javadoc), and use that one.
Vladimir Dyuzhev
A: 

Update: My original assumption was wrong, and to bad, the original exception/ message is thrown away, as far a i can see. The code where JODE fails looks like this:

 try {
      DataInputStream input = new DataInputStream
          (new BufferedInputStream
           (classpath.getFile(name.replace('.', '/') + ".class")));
        read(input, howMuch);            

  } catch (IOException ex) {
        String message = ex.getMessage();
      if ((howMuch & ~(FIELDS|METHODS|HIERARCHY
                       |INNERCLASSES|OUTERCLASSES)) != 0) {
          throw new NoClassDefFoundError(name);
        }

Since an IOException has to be thrown to get the NoClassDefFound, check anything regarding your IO subsytsem, e.g. the file.encoding. I guess you should patch JODE to get the detailed error message or debug to this point.

dz
I think we answered the same thing, in the same time..that is "remove the ".class" suffix :-))
Hypercube
I'm using jode-1.1-embedded.jar from sourceforge. I tried omitting the ".class", as well as using forward slashes (in windows it would be : d.setClassPath("C://mycode"); -- Still not working :(
Amir Afghani
A: 

This is a guess, as i don't fancy myself with decompiling classes, but i think that u should use

d.decompile("Test" , fw, p);

instead of what u are using now. This could be similar to

Class.forName("ClassName")

without the "class" suffix.

Hypercube
I've tried this, as I pointed out in the comment to my original post, and it did not work. Has anyone had any success trying this on their own?
Amir Afghani
Without knowing implementation details, it's hard to give an answer, but surely, the problem is that your "Test.class" param is NOT correct. As @dz suggested, u should investigate further at jode.bytecode.ClassInfo.loadInfo() or jode.decompiler.Decompiler.decompile() to see what's missing. Is it possible to debug?
Hypercube
I can't seem to decompile it. I have the sources and the class files, but when I step into the decompile function I don't jump into any sources. I think the debug symbols may have been stripped?
Amir Afghani
CORRECTION in last comment, I can't seem to debug it.
Amir Afghani
Jad is newer, I believe. At least I always use Jad. But it's a C++ application, of course...
Vladimir Dyuzhev
+1  A: 

I was able to reproduce the problem with all of the different binary versions of jode that are available from their web site. When I built a new version of jode using the mainline from svn, it worked fine. I also saw an entry in one of the jode forums where a user was complaining about the NoClassDefFound problem. His case sounded slightly different, but the jode developer suggested that he use the mainline from svn instead of the prebuild binary.

JZeeb
How did you get the mainline from SVN? On Jode's page, if I follow the link from the following text : "You can get the latest sources from the CVS repository. Follow the instruction on that page; use jode as modulename. If you want to checkout a specific version you can use the -r option:", I essentially get a 404.
Amir Afghani
Go to the jode page on sourceforge and click the Develop tab (or go straight to http://sourceforge.net/projects/jode/develop where you will find the svn information.
JZeeb