Revision: 1319
Author: sberlin
Date: Sun Oct 24 21:56:00 2010
Log: issue 407 -- better error messaging for failed interception.
previously exploded with a ComputationException, now uses a
ConfigurationException with a good msg.
http://code.google.com/p/google-guice/source/detail?r=1319
Modified:
/trunk/core/src/com/google/inject/internal/ConstructionProxyFactory.java
/trunk/core/src/com/google/inject/internal/Errors.java
/trunk/core/src/com/google/inject/internal/ProxyFactory.java
/trunk/core/test/com/google/inject/MethodInterceptionTest.java
=======================================
---
/trunk/core/src/com/google/inject/internal/ConstructionProxyFactory.java
Sat Jun 6 10:51:27 2009
+++
/trunk/core/src/com/google/inject/internal/ConstructionProxyFactory.java
Sun Oct 24 21:56:00 2010
@@ -26,5 +26,5 @@
/**
* Gets a construction proxy for the given constructor.
*/
- ConstructionProxy<T> create();
-}
+ ConstructionProxy<T> create() throws ErrorsException;
+}
=======================================
--- /trunk/core/src/com/google/inject/internal/Errors.java Sat Jul 31
08:06:36 2010
+++ /trunk/core/src/com/google/inject/internal/Errors.java Sun Oct 24
21:56:00 2010
@@ -343,6 +343,10 @@
public Errors keyNotFullySpecified(TypeLiteral<?> typeLiteral) {
return addMessage("%s cannot be used as a key; It is not fully
specified.", typeLiteral);
}
+
+ public Errors errorEnhancingClass(Class<?> clazz, Throwable cause) {
+ return errorInUserCode(cause, "Unable to method intercept: %s", clazz);
+ }
public static Collection<Message> getMessagesFromThrowable(Throwable
throwable) {
if (throwable instanceof ProvisionException) {
=======================================
--- /trunk/core/src/com/google/inject/internal/ProxyFactory.java Sat Jul 3
08:51:31 2010
+++ /trunk/core/src/com/google/inject/internal/ProxyFactory.java Sun Oct 24
21:56:00 2010
@@ -23,6 +23,7 @@
import com.google.inject.internal.util.Lists;
import com.google.inject.internal.util.Maps;
import com.google.inject.spi.InjectionPoint;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -147,7 +148,7 @@
return interceptors;
}
- public ConstructionProxy<T> create() {
+ public ConstructionProxy<T> create() throws ErrorsException {
if (interceptors.isEmpty()) {
return new
DefaultConstructionProxyFactory<T>(injectionPoint).create();
}
@@ -164,7 +165,7 @@
enhancer.setCallbackTypes(callbackTypes);
return new ProxyConstructor<T>(enhancer, injectionPoint, callbacks,
interceptors);
} catch (Throwable e) {
- throw new ProvisionException("Unable to method intercept: " +
declaringClass, e);
+ throw new Errors().errorEnhancingClass(declaringClass,
e).toException();
}
}
=======================================
--- /trunk/core/test/com/google/inject/MethodInterceptionTest.java Sat Jul
3 08:51:31 2010
+++ /trunk/core/test/com/google/inject/MethodInterceptionTest.java Sun Oct
24 21:56:00 2010
@@ -18,6 +18,7 @@
import com.google.inject.internal.util.ImmutableList;
import com.google.inject.internal.util.ImmutableMap;
+import com.google.inject.internal.util.Iterables;
import com.google.inject.matcher.Matchers;
import static com.google.inject.matcher.Matchers.only;
import com.google.inject.spi.ConstructorBinding;
@@ -101,6 +102,27 @@
interceptable.foo();
assertSame(interceptable, lastTarget.get());
}
+
+ public void testInterceptingFinalClass() {
+ Injector injector = Guice.createInjector(new AbstractModule() {
+ protected void configure() {
+ bindInterceptor(Matchers.any(), Matchers.any(), new
MethodInterceptor() {
+ public Object invoke(MethodInvocation methodInvocation) throws
Throwable {
+ return methodInvocation.proceed();
+ }
+ });
+ }
+ });
+ try {
+ injector.getInstance(NotInterceptable.class);
+ fail();
+ } catch(ConfigurationException ce) {
+ assertEquals("Unable to method intercept: " +
NotInterceptable.class.getName(),
+
Iterables.getOnlyElement(ce.getErrorMessages()).getMessage().toString());
+ assertEquals("Cannot subclass final class class " +
NotInterceptable.class.getName(),
+ ce.getCause().getMessage());
+ }
+ }
public void testSpiAccessToInterceptors() throws NoSuchMethodException {
Injector injector = Guice.createInjector(new AbstractModule() {
@@ -141,4 +163,6 @@
return new Bar() {};
}
}
-}
+
+ public static final class NotInterceptable {}
+}
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to google-guice-...@googlegroups.com.
To unsubscribe from this group, send email to
google-guice-dev+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en.