RFR: 8253178: Replace LinkedList Impl in net.http.FilterFactory

Sergei Ustimenko github.com+5709644+fdesu at openjdk.java.net
Fri Jul 9 08:21:57 UTC 2021


On Thu, 8 Jul 2021 10:38:33 GMT, Sergei Ustimenko <github.com+5709644+fdesu at openjdk.org> wrote:

> This patch replaces a LinkedList data structure used in the net.http.FilterFactory class with an ArrayList. This issue relates to [JDK-8246048: Replace LinkedList with ArrayLists in java.net.](https://bugs.openjdk.java.net/browse/JDK-8246048).
> 
> The list created once per HttpClient and filled with upfront known values (3 of them in the jdk.internal.net.http.HttpClientImpl#initFilters: AuthenticationFilter.class, RedirectFilter.class and depending on the presence of a cookieHandler - a CookieFilter.class).

src/java.net.http/share/classes/jdk/internal/net/http/FilterFactory.java line 40:

> 38:     }
> 39: 
> 40:     List<HeaderFilter> getFilterChain() {

I was thinking about the ways how FilterChain could be simplified. I played around with the `List<Supplier<HeaderFilter>>` instead of `List<Class<? extends HeaderFilter>>` and it seems that such change might improve the FilterFactory: 

    List<HeaderFilter> getFilterChain() {
        return filterSuppliers.stream()
                .map(Supplier::get)
                .toList();
    }

There is no constructor reflective access anymore, hence no exception handling.
Drawback here would be that HttpClientImpl in the `initFilters` will need to add suppliers vs classes i.e. `filters.addFilter(AuthenticationFilter::new);` vs `addFilter(AuthenticationFilter.class);`.

I think FilterFactory looks a bit simpler this way. 
What do you think, should we go ahead with the change?

-------------

PR: https://git.openjdk.java.net/jdk/pull/4721


More information about the net-dev mailing list