Skip to content

Commit

Permalink
OWB - correct unproxy instance
Browse files Browse the repository at this point in the history
  • Loading branch information
skybber committed Jun 18, 2020
1 parent 317f2e8 commit 7bf4c58
Showing 1 changed file with 14 additions and 4 deletions.
Expand Up @@ -55,7 +55,9 @@
import org.apache.webbeans.container.InjectableBeanManager;
import org.apache.webbeans.container.InjectionTargetFactoryImpl;
import org.apache.webbeans.portable.AnnotatedElementFactory;
import org.apache.webbeans.proxy.NormalScopeProxyFactory;
import org.apache.webbeans.proxy.OwbInterceptorProxy;
import org.apache.webbeans.proxy.OwbNormalScopeProxy;
import org.apache.webbeans.spi.BeanArchiveService.BeanArchiveInformation;
import org.apache.webbeans.spi.BeanArchiveService.BeanDiscoveryMode;
import org.hotswap.agent.logging.AgentLogger;
Expand Down Expand Up @@ -257,6 +259,7 @@ private static void createAnnotatedTypeForExistingBeanClass(BeanManagerImpl bean
private static void doReinjectRegisteredBeanInstances(BeanManagerImpl beanManager, InjectionTargetBean bean) {
for (Object instance: HaCdiCommons.getBeanInstances(bean)) {
if (instance != null) {
instance = unwrapInstance(beanManager, instance);
bean.getProducer().inject(instance, beanManager.createCreationalContext(bean));
LOGGER.info("Bean '{}' injection points was reinjected.", bean.getBeanClass().getName());
} else {
Expand All @@ -269,15 +272,22 @@ private static void doReinjectRegisteredBeanInstances(BeanManagerImpl beanManage
private static void doReinjectBeanInstance(BeanManagerImpl beanManager, InjectionTargetBean bean, Context context) {
Object instance = context.get(bean);
if (instance != null) {
if (instance instanceof OwbInterceptorProxy) {
instance = beanManager.getWebBeansContext().getInterceptorDecoratorProxyFactory().unwrapInstance(instance);
}

instance = unwrapInstance(beanManager, instance);
bean.getProducer().inject(instance, beanManager.createCreationalContext(bean));
LOGGER.info("Bean '{}' injection points was reinjected.", bean.getBeanClass().getName());
}
}

private static Object unwrapInstance(BeanManagerImpl beanManager, Object instance) {
if (instance instanceof OwbNormalScopeProxy) {
instance = NormalScopeProxyFactory.unwrapInstance(instance);
}
if (instance instanceof OwbInterceptorProxy) {
instance = beanManager.getWebBeansContext().getInterceptorDecoratorProxyFactory().unwrapInstance(instance);
}
return instance;
}

private static void doReloadBeanInBeanContexts(BeanManagerImpl beanManager, InjectionTargetBean<?> bean) {
try {
Map<Class<? extends Annotation>, Context> singleContextMap = getSingleContextMap(beanManager);
Expand Down

0 comments on commit 7bf4c58

Please sign in to comment.