Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1226

Unexpected behavior of negative priorities in container filters

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Duplicate Issue
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Steps to Reproduce:
      Hide

      Implement 2 filters:

      @Priority(Integer.MIN_VALUE)
      @Provider
      public final class LoggingFilter implements ContainerRequestFilter, ContainerResponseFilter

      {...}

      and

      @Priority(Integer.MIN_VALUE + 1)
      @Provider
      public final class OtherFilter implements ContainerRequestFilter, ContainerResponseFilter {...}

      The execution order of the ContainerResponseFilters is not predicable. Changing the annotations to @Priority(0) and @Priority(1) works fine.

      Show
      Implement 2 filters: @Priority(Integer.MIN_VALUE) @Provider public final class LoggingFilter implements ContainerRequestFilter, ContainerResponseFilter {...} and @Priority(Integer.MIN_VALUE + 1) @Provider public final class OtherFilter implements ContainerRequestFilter, ContainerResponseFilter {...} The execution order of the ContainerResponseFilters is not predicable. Changing the annotations to @Priority(0) and @Priority(1) works fine.

      Description

      Annotation a class that implements ContainerRequestFilter with @Priority(Integer.MIN_VALUE) works as expected. The filter is executed first. For ContainerResponseFilter it is executed in random order.

      Priority values should generally be non-negative, with negative values reserved for special meanings such as "undefined" or "not specified". A specification that defines use of the Priority annotation may define the range of allowed priorities and any priority values with special meaning.

      In this case the behaviour for negative Priorities is inconsistent between the 2 container filters. The correct way to work around this is to annotate:

      @Priority(0)

      Even though: many internet tutorials suggest:

      @Priority(Integer.MIN_VALUE)

      The implemntation oif logging filter in Glassfish does that too: https://github.com/jersey/jersey/blob/master/core-common/src/main/java/org/glassfish/jersey/filter/LoggingFilter.java

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  bill.burke Bill Burke
                  Reporter:
                  kenyakorn Andreas Redmer
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: