Skip to content

ContainerResponseFilter with @Priority(Integer.MIN_VALUE) will be actually invoked with max priority #44229

@dteleguin

Description

@dteleguin

Describe the bug

According to the specification:

Execution chains for extension points ContainerResponse and ClientResponse are sorted in descending order; the higher the number the higher the priority. These rules ensure that response filters are executed in reversed order of request filters.

With Quarkus REST (and previously Resteasy Reactive), a ContainerResponseFilter having @Priority(Integer.MIN_VALUE) will be actually invoked the first in the chain, even before @Priority(Integer.MIN_VALUE). This is opposite to Resteasy Classic, where it would be executed the last.

Thus, migration to Quarkus REST could break projects that depend on filter ordering and use @Priority(Integer.MIN_VALUE) to ensure minimal priority for the filters.

Expected behavior

The filters should be invoked in the following order:

N @Priority
1 Integer.MAX_VALUE
2 Priorities.USER
3 0
4 Integer.MIN_VALUE + 1
5 Integer.MIN_VALUE

Actual behavior

The filters are invoked in the following order:

N @Priority
1 Integer.MIN_VALUE
2 Integer.MAX_VALUE
3 Priorities.USER
4 0
5 Integer.MIN_VALUE + 1

How to Reproduce?

Reproducer: https://github.com/dteleguin/filter-priority-poc

./mvnw -Presteasy-classic clean test

2024-10-31 14:05:10,149 INFO  [io.quarkus] (main) filter-priority-poc 1.0.0-SNAPSHOT on JVM (powered by Quarkus 3.16.1) started in 2.944s. Listening on: http://localhost:8081
2024-10-31 14:05:10,152 INFO  [io.quarkus] (main) Profile test activated. 
2024-10-31 14:05:10,152 INFO  [io.quarkus] (main) Installed features: [cdi, resteasy, resteasy-jackson, smallrye-context-propagation, vertx]
2024-10-31 14:05:11,379 INFO  [org.acm.fil.FilterMAX] (executor-thread-1) filter
2024-10-31 14:05:11,379 INFO  [org.acm.fil.FilterDEF] (executor-thread-1) filter
2024-10-31 14:05:11,380 INFO  [org.acm.fil.Filter0] (executor-thread-1) filter
2024-10-31 14:05:11,380 INFO  [org.acm.fil.FilterMIN1] (executor-thread-1) filter
2024-10-31 14:05:11,380 INFO  [org.acm.fil.FilterMIN] (executor-thread-1) filter

./mvnw -Presteasy-reactive clean test

2024-10-31 14:05:49,341 INFO  [io.quarkus] (main) filter-priority-poc 1.0.0-SNAPSHOT on JVM (powered by Quarkus 3.16.1) started in 3.348s. Listening on: http://localhost:8081
2024-10-31 14:05:49,344 INFO  [io.quarkus] (main) Profile test activated. 
2024-10-31 14:05:49,344 INFO  [io.quarkus] (main) Installed features: [cdi, rest, smallrye-context-propagation, vertx]
2024-10-31 14:05:50,678 INFO  [org.acm.fil.FilterMIN] (executor-thread-1) filter
2024-10-31 14:05:50,678 INFO  [org.acm.fil.FilterMAX] (executor-thread-1) filter
2024-10-31 14:05:50,679 INFO  [org.acm.fil.FilterDEF] (executor-thread-1) filter
2024-10-31 14:05:50,679 INFO  [org.acm.fil.Filter0] (executor-thread-1) filter
2024-10-31 14:05:50,679 INFO  [org.acm.fil.FilterMIN1] (executor-thread-1) filter

Output of uname -a or ver

No response

Output of java -version

java version "21.0.1" 2023-10-17 LTS

Quarkus version or git rev

3.16.1

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.9

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions