eclipse-ee4j / eclipse-ee4j/jersey

Method register(class, priority) is not retaining the default priority

Open
#2,912 7 comments 0 reactions 0 assignees View on GitHub
Component: core Priority: Critical Type: Bug
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

Using the root ResourceConfig in a servlet 3.0 container, calling register(class, priority) has the same effect as calling register(class).

Summary as I see it

1. The classes are registered correctly in a ComponentBag.
2. That component bag is passed to new RuntimeConfig and a copy is made.
3. At the end of the constructor the classes are registered again (externalClasses).
4. It appears this second registration wins out over the original.

I should note that this works fine with the annotations. You must not use annotations to recreate this scenario.

Since the ordering of the filters is arbitrary in this bug, you may have to reverse the priorities to see that the ordering of the println doesn't change.

```
@ApplicationPath("/rest")
public class APIApplication extends ResourceConfig {
public APIApplication() {

//switching the 1 and 2 below does not reorder the filters, ordering appears to be completely based on a java Set, which is arbitrary. register(Filter1.class, 1);
register(Filter2.class, 2);
register(HelloEndpoint.class);
}
public static class Filter1 implements ContainerRequestFilter {
public void filter(ContainerRequestContext request) {
System.out.println("Filter 1");
}
}
public static class Filter2 implements ContainerRequestFilter {
public void filter(ContainerRequestContext request) {
System.out.println("Filter 2");
}
}

@Path("/hello")
public static class HelloEndpoint {
@GET @Produces({MediaType.TEXT_PLAIN})
public String sayHello(){
return "Hello World";
}
}
}
```
#### Environment
linux, tomcat8, openjdk 7, servlet 3.x
#### Affected Versions
[2.12]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.