Quarkus: Stereotypes are not taken into account when placed on methods

Created on 28 Jan 2020  路  5Comments  路  Source: quarkusio/quarkus

This doesn't work:

@Stereotype
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(value = RUNTIME)
@LoggingInterceptorBinding
public @interface Logged {
}
@Interceptor
@LoggingInterceptorBinding
public class LoggingInterceptor {
    @AroundInvoke
    public Object intercept(InvocationContext context) throws Exception {
        System.out.println("!!! Logging interceptor");
        return context.proceed();
    }
}
@ApplicationScoped
public class BeanA {
    @Logged
    public void methodA() {
        System.out.println("methodA called");
    }
}

The LoggingInterceptor will only get applied after I move the @Logged annotation from methodA to class level.

arearc kinbug triaginvalid

Most helpful comment

Ok, I'll have a look and come up with a PR

All 5 comments

CC @mkouba @manovotn

This should not work. Stereotypes can only be applied to a bean definition (bean class, producers). See https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#declaring_stereotypes for more information.

Ha! You're right. I was being too quick, apologies.
Anyway, perhaps could we detect this and throw a javax.enterprise.inject.spi.DefinitionException if a stereotype is applied to non-producer method? I think this would fall under

Definition errors - occur when a single bean definition violates the rules of this specification. If a definition error exists, the container must throw a subclass of javax.enterprise.inject.spi.DefinitionException.

No problem at all!

perhaps could we detect this

Good point. ArC does a lot less validation than for example Weld. But we should improve this little by little. For the record - this validation is not even required by the spec ;-).

Ok, I'll have a look and come up with a PR

Was this page helpful?
0 / 5 - 0 ratings