Issue 29 in guiceyfruit: com.google.inject.spi.CachedValue

0 views
Skip to first unread message

codesite...@google.com

unread,
Oct 24, 2009, 2:45:57 PM10/24/09
to guiceyf...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 29 by mathieu.carbou: com.google.inject.spi.CachedValue
http://code.google.com/p/guiceyfruit/issues/detail?id=29

Hi,

The Injectors class cast Provider to CachedValue to close objets. I am
using GuiceyFruit with the official Guice 2 release, which does not contain
this class.

I was wondering if it is safe to replace this method:


private static void closeBinding(Key<?> key, Binding<?> binding, Class<?
extends Annotation> scopeAnnotationToClose, Closer closer, CloseErrors
errors) {
Provider<?> provider = binding.getProvider();
Class<? extends Annotation> scopeAnnotation =
getScopeAnnotation(binding);
if (scopeAnnotation != null &&
scopeAnnotation.equals(scopeAnnotationToClose) && provider instanceof
CachedValue) {
CachedValue cachedValue = (CachedValue) provider;
Object value = cachedValue.getCachedValue();
if (value != null) {
Closers.close(key, value, closer, errors);
}
}
}

by this one:

Provider<?> provider = binding.getProvider();
Class<? extends Annotation> scopeAnnotation = getScopeAnnotation(binding);
if (scopeAnnotation != null &&
scopeAnnotation.equals(scopeAnnotationToClose)) {
Object value = provider.get();
if (value != null) {
Closers.close(key, value, closer, errors);
}
}

Thanks a lot !

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

Reply all
Reply to author
Forward
0 new messages