Skip to content

Commit

Permalink
WELD-2263 Implement ProcessBeanAttributes.ignoreFinalMethods()
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Dec 13, 2016
1 parent 74eda4a commit 1f8fa59
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
11 changes: 11 additions & 0 deletions impl/src/main/java/org/jboss/weld/bean/AbstractBean.java
Expand Up @@ -59,6 +59,8 @@ public abstract class AbstractBean<T, S> extends RIBean<T> {

private Producer<T> producer;

private boolean ignoreFinalMethods;

/**
* Constructor
*
Expand Down Expand Up @@ -237,4 +239,13 @@ public Producer<T> getProducer() {
public void setProducer(Producer<T> producer) {
this.producer = producer;
}

public boolean isIgnoreFinalMethods() {
return ignoreFinalMethods;
}

public void setIgnoreFinalMethods() {
this.ignoreFinalMethods = true;
}

}
Expand Up @@ -316,6 +316,9 @@ protected <T, S> boolean fireProcessBeanAttributes(AbstractBean<T, S> bean) {
bean.setAttributes(ExternalBeanAttributesFactory.<T>of(event.getBeanAttributesInternal(), manager));
bean.checkSpecialization();
}
if (event.isIgnoreFinalMethods()) {
bean.setIgnoreFinalMethods();
}
return false;
}
}
Expand Up @@ -56,6 +56,7 @@ private ProcessBeanAttributesImpl(BeanManagerImpl beanManager, BeanAttributes<T>
private BeanAttributesConfiguratorImpl<T> configurator;
private boolean veto;
private boolean dirty;
private boolean ignoreFinalMethods;

// we need this to ensure that configurator and set method are not invoked within one observer
private boolean beanAttributesSet;
Expand Down Expand Up @@ -109,7 +110,7 @@ public void veto() {

@Override
public void ignoreFinalMethods() {
// TODO WELD-2263
ignoreFinalMethods = true;
}

public boolean isVeto() {
Expand All @@ -120,6 +121,10 @@ public boolean isDirty() {
return dirty;
}

public boolean isIgnoreFinalMethods() {
return ignoreFinalMethods;
}

@Override
public void postNotify(Extension extension) {
super.postNotify(extension);
Expand Down
14 changes: 14 additions & 0 deletions impl/src/main/java/org/jboss/weld/util/Beans.java
Expand Up @@ -63,6 +63,7 @@
import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedConstructor;
import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedMethod;
import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType;
import org.jboss.weld.bean.AbstractBean;
import org.jboss.weld.bean.AbstractProducerBean;
import org.jboss.weld.bean.DecoratorImpl;
import org.jboss.weld.bean.InterceptorImpl;
Expand Down Expand Up @@ -649,6 +650,19 @@ public static BeanIdentifier getIdentifier(Contextual<?> contextual, ServiceRegi
return getIdentifier(contextual, null, serviceRegistry);
}

/**
*
* @param bean
* @return <code>true</code> if final methods should be ignored when checking proxyability
*/
public static boolean shouldIgnoreFinalMethods(Bean<?> bean) {
if (bean instanceof AbstractBean<?, ?>) {
AbstractBean<?, ?> abstractBean = (AbstractBean<?, ?>) bean;
return abstractBean.isIgnoreFinalMethods();
}
return false;
}

/**
* A slightly optimized way to get the bean identifier - there is not need to call ContextualStore.putIfAbsent() for passivation capable beans because it's
* already called during bootstrap. See also {@link BeanManagerImpl#addBean(Bean)}.
Expand Down
4 changes: 2 additions & 2 deletions impl/src/main/java/org/jboss/weld/util/Proxies.java
Expand Up @@ -42,7 +42,7 @@
import org.jboss.weld.util.reflection.Reflections;

/**
* Utilities for working with Javassist proxies
* Utilities for working with proxies.
*
* @author Nicklas Karlsson
* @author Pete Muir
Expand Down Expand Up @@ -219,7 +219,7 @@ private static UnproxyableResolutionException getUnproxyableClassException(Class
} else {
Method finalMethod = Reflections.getNonPrivateNonStaticFinalMethod(clazz);
if (finalMethod != null) {
if (services.get(WeldConfiguration.class).isFinalMethodIgnored(clazz.getName())) {
if (Beans.shouldIgnoreFinalMethods(declaringBean) || services.get(WeldConfiguration.class).isFinalMethodIgnored(clazz.getName())) {
ValidatorLogger.LOG.notProxyableFinalMethodIgnored(finalMethod, getDeclaringBeanInfo(declaringBean));
} else {
return ValidatorLogger.LOG.notProxyableFinalMethod(clazz, finalMethod, getDeclaringBeanInfo(declaringBean));
Expand Down
7 changes: 0 additions & 7 deletions jboss-tck-runner/src/test/tck20/tck-tests.xml
Expand Up @@ -123,13 +123,6 @@
</methods>
</class>

<!-- WELD-2263 -->
<class name="org.jboss.cdi.tck.tests.extensions.lifecycle.processBeanAttributes.ignoreFinalMethods.IgnoreFinalMethodsTest">
<methods>
<exclude name=".*"/>
</methods>
</class>

<!-- WELD-2264 -->
<class name="org.jboss.cdi.tck.tests.extensions.configurators.annotatedTypeConfigurator.beforeBeanDiscovery.AnnotatedTypeConfiguratorInBBDTest">
<methods>
Expand Down

0 comments on commit 1f8fa59

Please sign in to comment.