Revision: 1115 Author: limpbizkit Date: Tue Oct 6 11:22:39 2009 Log: Use a marker interface rather than the Proxy APIs to discover if returned singletons are circular-dependency proxies http://code.google.com/p/google-guice/source/detail?r=1115
Added: /trunk/src/com/google/inject/internal/CircularDependencyProxy.java Modified: /trunk/src/com/google/inject/Scopes.java /trunk/src/com/google/inject/internal/ConstructionContext.java /trunk/src/com/google/inject/internal/ContextualCallable.java /trunk/src/com/google/inject/internal/DelegatingInvocationHandler.java ======================================= --- /dev/null +++ /trunk/src/com/google/inject/internal/CircularDependencyProxy.java Tue Oct 6 11:22:39 2009 @@ -0,0 +1,24 @@ +/** + * Copyright (C) 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.inject.internal; + +/** + * @author [email protected] (Jesse Wilson) + */ +public interface CircularDependencyProxy { + // marker interface +} ======================================= --- /trunk/src/com/google/inject/Scopes.java Mon Oct 5 14:54:38 2009 +++ /trunk/src/com/google/inject/Scopes.java Tue Oct 6 11:22:39 2009 @@ -16,12 +16,11 @@ package com.google.inject; -import com.google.inject.internal.DelegatingInvocationHandler; +import com.google.inject.internal.CircularDependencyProxy; import com.google.inject.internal.InjectorBuilder; import com.google.inject.internal.LinkedBindingImpl; import com.google.inject.spi.BindingScopingVisitor; import java.lang.annotation.Annotation; -import java.lang.reflect.Proxy; /** * Built-in scope implementations. @@ -62,14 +61,13 @@ synchronized (InjectorBuilder.class) { if (instance == null) { T provided = creator.get(); - Object providedOrSentinel = (provided == null) ? NULL : provided; // don't remember proxies; these exist only to serve circular dependencies - if (Proxy.isProxyClass(providedOrSentinel.getClass()) && Proxy.getInvocationHandler( - providedOrSentinel) instanceof DelegatingInvocationHandler) { + if (provided instanceof CircularDependencyProxy) { return provided; } + Object providedOrSentinel = (provided == null) ? NULL : provided; if (instance != null && instance != providedOrSentinel) { throw new ProvisionException( "Provider was reentrant while creating a singleton"); ======================================= --- /trunk/src/com/google/inject/internal/ConstructionContext.java Mon Oct 5 14:54:38 2009 +++ /trunk/src/com/google/inject/internal/ConstructionContext.java Tue Oct 6 11:22:39 2009 @@ -75,7 +75,7 @@ ClassLoader classLoader = BytecodeGen.getClassLoader(expectedType); return expectedType.cast(Proxy.newProxyInstance(classLoader, - new Class[] { expectedType }, invocationHandler)); + new Class[] { expectedType, CircularDependencyProxy.class }, invocationHandler)); } public void setProxyDelegates(T delegate) { ======================================= --- /trunk/src/com/google/inject/internal/ContextualCallable.java Sat Jun 6 10:51:27 2009 +++ /trunk/src/com/google/inject/internal/ContextualCallable.java Tue Oct 6 11:22:39 2009 @@ -18,7 +18,7 @@ /** * @author [email protected] (Bob Lee) -*/ + */ interface ContextualCallable<T> { T call(InternalContext context) throws ErrorsException; } ======================================= --- /trunk/src/com/google/inject/internal/DelegatingInvocationHandler.java Mon Oct 5 14:54:38 2009 +++ /trunk/src/com/google/inject/internal/DelegatingInvocationHandler.java Tue Oct 6 11:22:39 2009 @@ -20,7 +20,7 @@ import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; -public class DelegatingInvocationHandler<T> implements InvocationHandler { +class DelegatingInvocationHandler<T> implements InvocationHandler { private T delegate; --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "google-guice-dev" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-guice-dev?hl=en -~----------~----~----~----~------~----~------~--~---
