linkedin / dexmaker

A utility for doing compile or runtime code generation targeting Android's Dalvik VM
Apache License 2.0
1.88k stars 249 forks source link

When using ProxyBuilder#withSharedClassLoader(), the proxy classes for the same class will be the same even though different interfaces are specified by implementing() #124

Closed tmurakami closed 5 years ago

tmurakami commented 5 years ago
public class ProxyBuilderTest {

    @Test
    public void test() throws IOException {
        Class<?> c1 = ProxyBuilder.forClass(C.class)
                                  .implementing(I1.class)
                                  .withSharedClassLoader()
                                  .buildProxyClass();
        Class<?> c2 = ProxyBuilder.forClass(C.class)
                                  .implementing(I2.class)
                                  .withSharedClassLoader()
                                  .buildProxyClass();
        assertNotSame(c1, c2); // java.lang.AssertionError: expected not same
    }

    static class C {
    }

    interface I1 {
    }

    interface I2 {
    }

}
moltmann commented 5 years ago

yes. We need to consider the interfaces when we generate the file name for the class in Dexmaker#generateFileName

Do you want to add the test and fix?

tmurakami commented 5 years ago

I guess the cause of this issue is that ProxyBuilder#getMethodNameForProxyOf() returns the same value. I wonder if we need to modify DexMaker#generateFileName().

Anyway, I will try sending a PR.