Search in sources :

Example 1 with IllegalArgumentException

use of org.jboss.weld.exceptions.IllegalArgumentException in project core by weld.

the class BeanConfiguratorExtension method afterBeanDiscovery.

void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager) {
    event.addBean().scope(Dependent.class).addType(String.class).addQualifier(Juicy.Literal.INSTANCE).produceWith((i) -> {
        InjectionPoint ip = i.select(InjectionPoint.class).get();
        assertNotNull(ip);
        assertNotNull(ip.getBean());
        return ip.getBean().getBeanClass().getName();
    });
    event.addBean().scope(ApplicationScoped.class).addType(Map.class).addQualifier(Juicy.Literal.INSTANCE).produceWith((i) -> {
        try {
            i.select(InjectionPoint.class).get();
            fail("Cannot inject injection point metadata into non-dependent bean");
        } catch (IllegalArgumentException expected) {
        }
        return new HashMap<>();
    });
}
Also used : InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) HashMap(java.util.HashMap) Dependent(javax.enterprise.context.Dependent) ApplicationScoped(javax.enterprise.context.ApplicationScoped) IllegalArgumentException(org.jboss.weld.exceptions.IllegalArgumentException)

Example 2 with IllegalArgumentException

use of org.jboss.weld.exceptions.IllegalArgumentException in project core by weld.

the class AbstractProducerFactory method createProducer.

@Override
public <T> Producer<T> createProducer(Bean<T> bean) {
    if (getDeclaringBean() == null && !getAnnotatedMember().isStatic()) {
        throw BeanManagerLogger.LOG.nullDeclaringBean(getAnnotatedMember());
    }
    AnnotatedTypeValidator.validateAnnotatedMember(getAnnotatedMember());
    try {
        Producer<T> producer = createProducer(getDeclaringBean(), bean, null);
        getManager().getServices().get(InjectionTargetService.class).validateProducer(producer);
        return producer;
    } catch (Throwable e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : InjectionTargetService(org.jboss.weld.injection.producer.InjectionTargetService) IllegalArgumentException(org.jboss.weld.exceptions.IllegalArgumentException)

Aggregations

IllegalArgumentException (org.jboss.weld.exceptions.IllegalArgumentException)2 HashMap (java.util.HashMap)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Dependent (javax.enterprise.context.Dependent)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 InjectionTargetService (org.jboss.weld.injection.producer.InjectionTargetService)1