1010import java .util .WeakHashMap ;
1111
1212import top .niunaijun .blackreflection .annotation .BClass ;
13+ import top .niunaijun .blackreflection .annotation .BClassName ;
14+ import top .niunaijun .blackreflection .annotation .BClassNameNotProcess ;
1315import top .niunaijun .blackreflection .annotation .BConstructor ;
1416import top .niunaijun .blackreflection .annotation .BConstructorNotProcess ;
1517import top .niunaijun .blackreflection .annotation .BField ;
1820import top .niunaijun .blackreflection .annotation .BFieldSetNotProcess ;
1921import top .niunaijun .blackreflection .annotation .BMethodCheckNotProcess ;
2022import top .niunaijun .blackreflection .annotation .BParamClass ;
21- import top .niunaijun .blackreflection .annotation .BClassName ;
22- import top .niunaijun .blackreflection .annotation .BClassNameNotProcess ;
2323import top .niunaijun .blackreflection .annotation .BParamClassName ;
2424import top .niunaijun .blackreflection .utils .Reflector ;
2525
@@ -36,6 +36,7 @@ public class BlackReflection {
3636 public static boolean DEBUG = false ;
3737 public static boolean CACHE = false ;
3838 private static final Map <Class <?>, Object > sProxyCache = new HashMap <>();
39+ private static final Map <Class <?>, Object > sProxyWithExceptionCache = new HashMap <>();
3940
4041 // key caller
4142 private static final WeakHashMap <Object , Map <Class <?>, Object >> sCallerProxyCache = new WeakHashMap <>();
@@ -163,16 +164,11 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
163164 }
164165 });
165166
166- if (CACHE ) {
167- if (caller == null ) {
168- sProxyCache .put (clazz , o );
167+ if (caller == null ) {
168+ if (withException ) {
169+ sProxyWithExceptionCache .put (clazz , o );
169170 } else {
170- Map <Class <?>, Object > callerClassMap = sCallerProxyCache .get (caller );
171- if (callerClassMap == null ) {
172- callerClassMap = new HashMap <>();
173- sCallerProxyCache .put (caller , callerClassMap );
174- }
175- callerClassMap .put (clazz , o );
171+ sProxyCache .put (clazz , o );
176172 }
177173 }
178174 return (T ) o ;
@@ -183,25 +179,16 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
183179 }
184180
185181 private static <T > T getProxy (Class <T > clazz , final Object caller , boolean withException ) {
186- if (!CACHE ) {
187- return null ;
188- }
189182 try {
190- if (! withException ) {
191- if ( caller == null ) {
192- Object o = sProxyCache . get ( clazz );
193- if ( o != null ) {
194- return ( T ) o ;
195- }
183+ if (caller == null ) {
184+ Object o ;
185+ if ( withException ) {
186+ o = sProxyWithExceptionCache . get ( clazz );
187+ } else {
188+ o = sProxyCache . get ( clazz );
196189 }
197- else {
198- Map <Class <?>, Object > callerClassMap = sCallerProxyCache .get (caller );
199- if (callerClassMap != null ) {
200- Object o = callerClassMap .get (clazz );
201- if (o != null ) {
202- return (T ) o ;
203- }
204- }
190+ if (o != null ) {
191+ return (T ) o ;
205192 }
206193 }
207194 } catch (Throwable ignore ) {
0 commit comments