Created
July 7, 2014 18:12
-
-
Save gissuebot/f7d7f873e2fd96e2233d to your computer and use it in GitHub Desktop.
Migrated attachment for Guice issue 343, comment 26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: src/com/google/inject/internal/DefaultConstructionProxyFactory.java | |
=================================================================== | |
--- src/com/google/inject/internal/DefaultConstructionProxyFactory.java (revision 1157) | |
+++ src/com/google/inject/internal/DefaultConstructionProxyFactory.java (working copy) | |
@@ -46,13 +46,14 @@ | |
// Use FastConstructor if the constructor is public. | |
if (Modifier.isPublic(constructor.getModifiers())) { | |
+ Class<T> classToConstruct = constructor.getDeclaringClass(); | |
/*if[AOP]*/ | |
- return new ConstructionProxy<T>() { | |
- Class<T> classToConstruct = constructor.getDeclaringClass(); | |
+ try { | |
final net.sf.cglib.reflect.FastConstructor fastConstructor | |
= BytecodeGen.newFastClass(classToConstruct, Visibility.forMember(constructor)) | |
.getConstructor(constructor); | |
+ return new ConstructionProxy<T>() { | |
@SuppressWarnings("unchecked") | |
public T newInstance(Object... arguments) throws InvocationTargetException { | |
return (T) fastConstructor.newInstance(arguments); | |
@@ -68,7 +69,11 @@ | |
return ImmutableMap.of(); | |
} | |
}; | |
+ } catch (net.sf.cglib.core.CodeGenerationException e) {/* fall-through */} | |
/*end[AOP]*/ | |
+ if (!Modifier.isPublic(classToConstruct.getModifiers())) { | |
+ constructor.setAccessible(true); | |
+ } | |
} else { | |
constructor.setAccessible(true); | |
} | |
Index: src/com/google/inject/internal/ProxyFactory.java | |
=================================================================== | |
--- src/com/google/inject/internal/ProxyFactory.java (revision 1157) | |
+++ src/com/google/inject/internal/ProxyFactory.java (working copy) | |
@@ -17,6 +17,8 @@ | |
package com.google.inject.internal; | |
import static com.google.inject.internal.BytecodeGen.newFastClass; | |
+ | |
+import com.google.inject.ProvisionException; | |
import com.google.inject.spi.InjectionPoint; | |
import java.lang.reflect.Constructor; | |
import java.lang.reflect.InvocationTargetException; | |
@@ -153,10 +155,14 @@ | |
// Create the proxied class. We're careful to ensure that all enhancer state is not-specific | |
// to this injector. Otherwise, the proxies for each injector will waste PermGen memory | |
+ try { | |
Enhancer enhancer = BytecodeGen.newEnhancer(declaringClass, visibility); | |
enhancer.setCallbackFilter(new IndicesCallbackFilter(declaringClass, methods)); | |
enhancer.setCallbackTypes(callbackTypes); | |
return new ProxyConstructor<T>(enhancer, injectionPoint, callbacks, interceptors); | |
+ } catch (Throwable e) { | |
+ throw new ProvisionException("Unable to method intercept: " + declaringClass, e); | |
+ } | |
} | |
private static class MethodInterceptorsPair { | |
Index: src/com/google/inject/internal/SingleMethodInjector.java | |
=================================================================== | |
--- src/com/google/inject/internal/SingleMethodInjector.java (revision 1157) | |
+++ src/com/google/inject/internal/SingleMethodInjector.java (working copy) | |
@@ -45,6 +45,7 @@ | |
int modifiers = method.getModifiers(); | |
if (!Modifier.isPrivate(modifiers) && !Modifier.isProtected(modifiers)) { | |
/*if[AOP]*/ | |
+ try { | |
final net.sf.cglib.reflect.FastMethod fastMethod | |
= BytecodeGen.newFastClass(method.getDeclaringClass(), Visibility.forMember(method)) | |
.getMethod(method); | |
@@ -55,10 +56,12 @@ | |
return fastMethod.invoke(target, parameters); | |
} | |
}; | |
+ } catch (net.sf.cglib.core.CodeGenerationException e) {/* fall-through */} | |
/*end[AOP]*/ | |
} | |
- if (!Modifier.isPublic(modifiers)) { | |
+ if (!Modifier.isPublic(modifiers) || | |
+ !Modifier.isPublic(method.getDeclaringClass().getModifiers())) { | |
method.setAccessible(true); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment