Skip to content

Commit

Permalink
WELD-2466: Relax unproxyable check in BM.getInjectableReference()
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Mar 2, 2018
1 parent 405a79b commit fa69aee
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@
import org.jboss.weld.util.Interceptors;
import org.jboss.weld.util.LazyValueHolder;
import org.jboss.weld.util.Preconditions;
import org.jboss.weld.util.Proxies;
import org.jboss.weld.util.Types;
import org.jboss.weld.util.collections.Iterables;
import org.jboss.weld.util.collections.WeldCollections;
Expand Down Expand Up @@ -906,10 +905,6 @@ public <T> Bean<T> getBean(Resolvable resolvable) {
if (bean == null) {
throw BeanManagerLogger.LOG.unresolvableElement(resolvable);
}

if (isNormalScope(bean.getScope()) && !Beans.isBeanProxyable(bean, this)) {
throw Proxies.getUnproxyableTypesException(bean, services);
}
return bean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

public class NotSimpleConstructorClass {

private String value;

public NotSimpleConstructorClass(String value) {
this.value = value;
}

protected String giveMeNothing() {
// dummy method
return "nothing";
}
}

public String getValue() {
return value;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.jboss.weld.tests.proxy.superclass.unproxyable;

import static org.junit.Assert.assertEquals;

import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Set;

import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.InjectionPoint;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.BeanArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.weld.test.util.Utils;
import org.jboss.weld.tests.proxy.superclass.NotSimpleConstructorClass;
import org.jboss.weld.tests.proxy.superclass.SimpleBean;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
*
* @author Martin Kouba
*/
@RunWith(Arquillian.class)
public class GetInjectableReferenceUnproxyableCheckTest {

@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(BeanArchive.class, Utils.getDeploymentNameAsHash(GetInjectableReferenceUnproxyableCheckTest.class))
.addPackage(GetInjectableReferenceUnproxyableCheckTest.class.getPackage()).addClasses(SimpleBean.class, NotSimpleConstructorClass.class);
}

@Test
public void testClientProxy(BeanManager beanManager) {
SimpleBean simple = (SimpleBean) beanManager.getInjectableReference(new InjectionPoint() {

@Override
public boolean isTransient() {
return false;
}

@Override
public boolean isDelegate() {
return false;
}

@Override
public Type getType() {
return SimpleBean.class;
}

@Override
public Set<Annotation> getQualifiers() {
return Collections.emptySet();
}

@Override
public Member getMember() {
return null;
}

@Override
public Bean<?> getBean() {
return null;
}

@Override
public Annotated getAnnotated() {
return null;
}
}, beanManager.createCreationalContext(null));

assertEquals("nothing", simple.getValue());
}

}

0 comments on commit fa69aee

Please sign in to comment.