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

Unexpected behavior of negative priorities in container filters

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Minor
    • None
    • None
    • None
    • None
    • 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

      Attachments

        Issue Links

          Activity

            People

              patriot1burke@gmail.com Bill Burke (Inactive)
              kenyakorn Andreas Redmer (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: