[jboss-jira] [JBoss JIRA] (WFLY-10754) NullPointerException using Stateless with configured interceptors

Luca Stancapiano (JIRA) issues at jboss.org
Sat Jul 28 06:17:00 EDT 2018


    [ https://issues.jboss.org/browse/WFLY-10754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13611810#comment-13611810 ] 

Luca Stancapiano commented on WFLY-10754:
-----------------------------------------

in my opinion it seems that weld filters some interceptors and ignores them if it has different types in the same stateless. In this case the OkInterceptor is ignored because it is not considered part of the CdiInterceptorFactory while it is considered a PlainInterceptorFactory. Here you find the function that performs this filter on the org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter of the weld-core-impl 3.0.4.Final project:

{code:java}
    private List<Interceptor<?>> extractCdiInterceptors(Collection<? extends InterceptorClassMetadata<?>> interceptorMetadatas) {
        // ignore interceptors which are not CDI interceptors
        ArrayList<Interceptor<?>> interceptors = new ArrayList<Interceptor<?>>();
        for (InterceptorClassMetadata<?> interceptorMetadata : interceptorMetadatas) {
            InterceptorFactory<?> interceptorFactory = interceptorMetadata.getInterceptorFactory();
            if (interceptorFactory instanceof CdiInterceptorFactory<?>) {
                CdiInterceptorFactory<?> cdiInterceptorFactory = (CdiInterceptorFactory<?>) interceptorFactory;
                interceptors.add(cdiInterceptorFactory.getInterceptor());
            }
        }
        return interceptors;
    }
{code}


> NullPointerException using Stateless with configured interceptors
> -----------------------------------------------------------------
>
>                 Key: WFLY-10754
>                 URL: https://issues.jboss.org/browse/WFLY-10754
>             Project: WildFly
>          Issue Type: Bug
>          Components: CDI / Weld
>    Affects Versions: 13.0.0.Final
>         Environment: WildFly 13.0.0.Final and java 10.0.1
>            Reporter: Luca Stancapiano
>            Assignee: Matej Novotny
>
> I report a strange behavior on WildFly 13 when configuring interceptors within stateless. Below I describe the scenario:
> Here a simple interceptor:
> {code:java}
> package it.vige.injection.interceptors;
> import javax.interceptor.AroundInvoke;
> import javax.interceptor.Interceptor;
> import javax.interceptor.InvocationContext;
> @Interceptor
> public class OKInterceptor {
> 	@AroundInvoke
> 	public Object aroundInvoke(InvocationContext ic) throws Exception {
> 		return ic.proceed();
> 	}
> }
> {code}
> Here an annotation used as interceptor binding:
> {code:java}
> package it.vige.injection.interceptors;
> import static java.lang.annotation.ElementType.CONSTRUCTOR;
> import static java.lang.annotation.ElementType.METHOD;
> import static java.lang.annotation.ElementType.TYPE;
> import static java.lang.annotation.RetentionPolicy.RUNTIME;
> import java.lang.annotation.Retention;
> import java.lang.annotation.Target;
> import javax.interceptor.InterceptorBinding;
> @Retention(RUNTIME)
> @Target({ METHOD, TYPE, CONSTRUCTOR })
> @InterceptorBinding
> public @interface NotOK {
> }
> {code}
> Here an interceptor annotated with the interceptor binding:
> {code:java}
> package it.vige.injection.interceptors;
> import javax.interceptor.AroundInvoke;
> import javax.interceptor.Interceptor;
> import javax.interceptor.InvocationContext;
> @Interceptor
> @NotOK
> public class NotOKInterceptor {
> 	@AroundInvoke
> 	public Object aroundInvoke(InvocationContext ic) throws Exception {
> 		return ic.proceed();
> 	}
> }
> {code}
> Here the stateless service configured with both the interceptors:
> {code:java}
> package it.vige.injection.interceptors;
> import javax.ejb.Stateless;
> import javax.interceptor.Interceptors;
> @Stateless
> public class SimpleService {
> 	@Interceptors({ OKInterceptor.class })
> 	public void ok() {
> 	}
> 	@NotOK
> 	public void notOk() {
> 	}
> }
> {code}
> This service must have two methods, one attached to the simple nterceptor and the other attached to the interceptor binding.
> Here the beans.xml configuration:
> {code:java}
> <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
> 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
>                            http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
> 	version="2.0" bean-discovery-mode="all">
> 	<interceptors>
> 		<class>it.vige.injection.interceptors.OKInterceptor</class>
> 		<class>it.vige.injection.interceptors.NotOKInterceptor</class>
> 	</interceptors>
> </beans>
> {code}
> And in the end the client who call the service:
> {code:java}
> ....
> 	@Inject
> 	private SimpleService simpleService;
> ...
>         // this call works:
>         simpleService.ok();
>         // this call starts a NullPointerException:
>         simpleService.notOk();
> ...
> {code}
> when I try to call the notOk method I get this exception:
> {code:java}
> javax.ejb.EJBException: java.lang.NullPointerException
> at deployment.test.war//it.vige.injection.test.InterceptorsTestCase.testNotOk(InterceptorsTestCase.java:52)
> Caused by: java.lang.NullPointerException
> at deployment.test.war//it.vige.injection.test.InterceptorsTestCase.testNotOk(InterceptorsTestCase.java:52)
> {code}
> The same thing was tested on WildFly 12.0.0.Final and it was ok.
> If on WildFfly 13.0.0.Final I remove the @Stateless annotation from the service it works



--
This message was sent by Atlassian JIRA
(v7.5.0#75005)


More information about the jboss-jira mailing list