PAMunb / JimpleFramework

A Rascal implementation of the Jimple framework.
13 stars 5 forks source link

Decompiling nested interfaces that spawns multiple class files #6

Closed faustocarva closed 3 years ago

faustocarva commented 3 years ago

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

rbonifacio commented 3 years ago

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?

rbonifacio commented 3 years ago

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

faustocarva commented 3 years ago

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

rbonifacio commented 3 years ago

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