From 3358dc269352383eb5e9c186d24ff4a292eeb637 Mon Sep 17 00:00:00 2001 From: chibash Date: Sun, 26 May 2013 23:26:16 +0900 Subject: fixed JASSIST-199 --- Readme.html | 4 +- src/main/javassist/util/proxy/ProxyFactory.java | 49 ++++++++++++++++++------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Readme.html b/Readme.html index f4c8b9a0..2cc92bb9 100644 --- a/Readme.html +++ b/Readme.html @@ -283,7 +283,9 @@ see javassist.Dump.

-version 3.18

-version 3.17.1 on December 3, 2012 diff --git a/src/main/javassist/util/proxy/ProxyFactory.java b/src/main/javassist/util/proxy/ProxyFactory.java index 88636c01..34d67179 100644 --- a/src/main/javassist/util/proxy/ProxyFactory.java +++ b/src/main/javassist/util/proxy/ProxyFactory.java @@ -700,10 +700,38 @@ public class ProxyFactory { setField(DEFAULT_INTERCEPTOR, handler); } - private static int counter = 0; + /** + * A unique class name generator. + */ + public static interface UniqueName { + /** + * Returns a unique class name. + * + * @param classname the super class name of the proxy class. + */ + String get(String classname); + } + + /** + * A unique class name generator. + * Replacing this generator changes the algorithm to generate a + * unique name. The get method does not have to be + * a synchronized method since the access to this field + * is mutually exclusive and thus thread safe. + */ + public static UniqueName nameGenerator = new UniqueName() { + private final String sep = "_$$_jvst" + Integer.toHexString(this.hashCode() & 0xfff) + "_"; + private int counter = 0; - private static synchronized String makeProxyName(String classname) { - return classname + "_$$_javassist_" + counter++; + public String get(String classname) { + return classname + sep + Integer.toHexString(counter++); + } + }; + + private static String makeProxyName(String classname) { + synchronized (nameGenerator) { + return nameGenerator.get(classname); + } } private ClassFile make() throws CannotCompileException { @@ -758,8 +786,7 @@ public class ProxyFactory { return cf; } - private void checkClassAndSuperName() - { + private void checkClassAndSuperName() { if (interfaces == null) interfaces = new Class[0]; @@ -780,8 +807,7 @@ public class ProxyFactory { basename = "org.javassist.tmp." + basename; } - private void allocateClassName() - { + private void allocateClassName() { classname = makeProxyName(basename); } @@ -796,8 +822,7 @@ public class ProxyFactory { } }; - private void makeSortedMethodList() - { + private void makeSortedMethodList() { checkClassAndSuperName(); hasGetHandler = false; // getMethods() may set this to true. @@ -838,8 +863,7 @@ public class ProxyFactory { this.signature = signature; } - private boolean testBit(byte[] signature, int idx) - { + private boolean testBit(byte[] signature, int idx) { int byteIdx = idx >> 3; if (byteIdx > signature.length) { return false; @@ -851,8 +875,7 @@ public class ProxyFactory { } } - private void setBit(byte[] signature, int idx) - { + private void setBit(byte[] signature, int idx) { int byteIdx = idx >> 3; if (byteIdx < signature.length) { int bitIdx = idx & 0x7; -- cgit v1.2.3