PAMunb/JimpleFramework

Decompiling nested interfaces that spawns multiple class files

faustocarva opened this issue · 4 comments

Hi, the Decompiler class has a problem when decompiling (bytecode to jimple) a class file that is originated from a source code (.java) which have a nested interface. Maybe the whole problem is related to the generation of multiples class files originated from java files. Below is the code that gives the error:

package samples;

interface MyInterfaceA{  
    void display();  
}  
      
class NestedInterface 
    implements MyInterfaceA{  
     public void display(){
         System.out.println("Nested interface method");
     }  
      
     public static void main(String args[]){  
         MyInterfaceA obj=
                 new NestedInterface(); 
      obj.display();  
     }  
}

I created a test case for this:

	@Test 
	public void decompileNestedInterface() {
		try {
			File classFile = new File("./target/test-classes/samples/NestedInterface.class"); 			
			assertNotNull(classFile);
			
			IValueFactory vf = ValueFactory.getInstance();
			Decompiler decompiler = new Decompiler(vf);
			IConstructor c = decompiler.decompile(new FileInputStream(classFile), null);
			
			assertNotNull(c);
		}
		catch(Exception e) {
			e.printStackTrace();
			fail(e.getLocalizedMessage());
		}
	}

And here the error:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running lang.jimple.internal.TestDecompiler
Tests run: 5, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.226 sec <<< FAILURE!
decompileNestedInterface(lang.jimple.internal.TestDecompiler)  Time elapsed: 0.023 sec  <<< ERROR!
java.lang.StackOverflowError
	at lang.jimple.internal.JimpleObjectFactory.type(JimpleObjectFactory.java:107)
	at lang.jimple.internal.JimpleObjectFactory.type(JimpleObjectFactory.java:127)
	at lang.jimple.internal.JimpleObjectFactory.type(JimpleObjectFactory.java:127)
	at lang.jimple.internal.JimpleObjectFactory.type(JimpleObjectFactory.java:127)

I came up with this error trying to process this simple file:

https://github.com/OpenFeign/feign/blob/819b2df8c54d9266abf4cde9b17ab7890ed95cc6/core/src/main/java/feign/stream/StreamDecoder.java

  • this code spawns to class files, one for StreamDecoder and other for the stream used inside.

Thanks for reporting @faustocarva. I was able to reproduce and fix this issue. Nonetheless, it was not related to nested classes or interfaces.

Could you please test this code again with the new code in the master branch?

In this particular example, the problem was occurring due to a bug while decompiling array types.

It worked. I will do a PR with this test case, all right?

Perfect @faustocarva . Please, send a PR with the test cases.