Skip to content

Commit

Permalink
Fixes linkedin#124: Add the hash of interfaces to the proxy class name
Browse files Browse the repository at this point in the history
  • Loading branch information
tmurakami authored and drewhannay committed Nov 15, 2018
1 parent 2a9362a commit 32b463e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assume.assumeTrue;

public class ProxyBuilderTest {
Expand Down Expand Up @@ -1239,4 +1240,15 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
assertEquals("fake E", proxy.returnE());

}

@Test
public void testImplementingDifferentInterfacesWithSharedClassLoader() throws IOException {
assumeTrue(Build.VERSION.SDK_INT >= 24);

Class<?> c1 = ProxyBuilder.forClass(SimpleClass.class)
.implementing(Runnable.class).withSharedClassLoader().buildProxyClass();
Class<?> c2 = ProxyBuilder.forClass(SimpleClass.class)
.implementing(Callable.class).withSharedClassLoader().buildProxyClass();
assertNotSame(c1, c2);
}
}
7 changes: 4 additions & 3 deletions dexmaker/src/main/java/com/android/dx/stock/ProxyBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public Class<? extends T> buildProxyClass() throws IOException {

// the cache missed; generate the class
DexMaker dexMaker = new DexMaker();
String generatedName = getMethodNameForProxyOf(baseClass);
String generatedName = getMethodNameForProxyOf(baseClass, interfaces);
TypeId<? extends T> generatedType = TypeId.get("L" + generatedName + ";");
TypeId<T> superType = TypeId.get(baseClass);
generateConstructorsAndFields(dexMaker, generatedType, superType, baseClass);
Expand Down Expand Up @@ -813,8 +813,9 @@ private void getMethodsToProxy(Set<MethodSetEntry> sink, Set<MethodSetEntry> see
}
}

private static <T> String getMethodNameForProxyOf(Class<T> clazz) {
return clazz.getName().replace(".", "/") + "_Proxy";
private static <T> String getMethodNameForProxyOf(Class<T> clazz, Set<Class<?>> interfaces) {
String interfacesHash = Integer.toHexString(interfaces.hashCode());
return clazz.getName().replace(".", "/") + "_" + interfacesHash + "_Proxy";
}

private static TypeId<?>[] classArrayToTypeArray(Class<?>[] input) {
Expand Down

0 comments on commit 32b463e

Please sign in to comment.