Quarkus: @IfBuildProfile not working on Interceptor

Created on 23 May 2020  路  10Comments  路  Source: quarkusio/quarkus

Describe the bug
When annotating an Interceptor (javax.interceptor.Interceptor) with io.quarkus.arc.profile.IfBuildProfile the Interceptor ist still active. I observed this with an Interceptor annotated with @IfBuildProfile("test") (for logging test executions) which was also enabled in devmode ( Probably due to #9352 ).

Expected behavior
Interceptor only active in test-Profile

Actual behavior
Interceptor active in Dev-Mode.

To Reproduce
Steps to reproduce the behavior:

  1. Add annotation @IfBuildProfile("test") to an Interceptor
  2. Get it on the dev-mode classpath
  3. Interceptor is active when run in dev-mode

Environment (please complete the following information):

  • Output of uname -a or ver: MSYS_NT-10.0-18363 XXX 3.0.7-338.x86_64 2019-11-21 23:07 UTC x86_64 Msys
  • Output of java -version:
    openjdk version "11.0.7" 2020-04-14 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.7+10) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.7+10, mixed mode)
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: `1.4.2.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
arearc kinenhancement

Most helpful comment

Still seems like the expected behavior to me

All 10 comments

Hi,

would you be kind enough to provide a small reproducer project exhibiting this behavior?

Reproducer: https://github.com/tkalmar/quarkus-reproduce-9546
The other way around: Interceptor annotated with '@IfBuildProfile("dev")'
./mvnw test leads to:
2020-05-23 16:33:11,506 INFO [org.acm.LogInterceptor] (main) Intercepting

So looking at your code I see something like:

@IfBuildProfile("dev")
@Priority(201)
@Interceptor
public class LogInterceptor {

    @AroundInvoke
    public Object invoke(InvocationContext ctx) throws Exception {
        // do something
    }
}

We don't state in the documentation that @IfBuildProfile and friends on interceptors, so I consider this a feature request more than a bug.

@manovotn @mkouba do you agree we add this capability? Do you foresee any problems?

@geoand @tkalmar @manovotn +1 for this feature. I think that we should probably change the current way of disabling beans (i.e. if the profile is not matching) from @Alternative without priority to @Vetoed. That would allow us to disable interceptors easily. I'll send a PR shortly.

Great!

Ah, I forgot that @Vetoed only works for types... We could use @Vetoed for classes and @Alternative for producers but then there would be a difference in behavior - alternatives merely exclude the bean from injection whereas @Vetoed excludes all observers and producers declared on the bean. On the other hand, I believe that it's the expected behavior - if you annotate a bean class with @IfBuildProfile("prod") and that class declares some producers you don't expect the producers to work in the test profile, right? @geoand @manovotn WDYT?

@mkouba exactly. I think there are also test cases that cover that scenario.

@geoand I'm sorry my description was not clear. Updated ^.

Still seems like the expected behavior to me

+1 for this feature

On the other hand, I believe that it's the expected behavior

Yea, same opinion here.

Was this page helpful?
0 / 5 - 0 ratings