From 21115d45121bc8ad3dd8e1f20499b7ada87573b4 Mon Sep 17 00:00:00 2001 From: jansupol Date: Thu, 16 Dec 2021 21:52:55 +0100 Subject: [PATCH] Prevent loading Feature/DynamicFeature services multiple times. Signed-off-by: jansupol --- .../org/glassfish/jersey/AbstractFeatureConfigurator.java | 3 ++- .../jersey/internal/DynamicFeatureConfigurator.java | 5 ++++- .../org/glassfish/jersey/internal/FeatureConfigurator.java | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/core-common/src/main/java/org/glassfish/jersey/AbstractFeatureConfigurator.java b/core-common/src/main/java/org/glassfish/jersey/AbstractFeatureConfigurator.java index dbc4308c3e..61b7eb5a95 100644 --- a/core-common/src/main/java/org/glassfish/jersey/AbstractFeatureConfigurator.java +++ b/core-common/src/main/java/org/glassfish/jersey/AbstractFeatureConfigurator.java @@ -24,6 +24,7 @@ import javax.ws.rs.RuntimeType; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; @@ -62,7 +63,7 @@ protected List> loadImplementations(Map applicationProp * @param features list of features to be registered * @param bootstrapBag place where features are being registered */ - protected void registerFeatures(List> features, + protected void registerFeatures(Collection> features, BootstrapBag bootstrapBag) { final List autoDiscoverables = new ArrayList<>(); diff --git a/core-common/src/main/java/org/glassfish/jersey/internal/DynamicFeatureConfigurator.java b/core-common/src/main/java/org/glassfish/jersey/internal/DynamicFeatureConfigurator.java index ed2c8fb9cb..f8ea86681e 100644 --- a/core-common/src/main/java/org/glassfish/jersey/internal/DynamicFeatureConfigurator.java +++ b/core-common/src/main/java/org/glassfish/jersey/internal/DynamicFeatureConfigurator.java @@ -22,8 +22,10 @@ import javax.ws.rs.RuntimeType; import javax.ws.rs.container.DynamicFeature; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; /** * Registers JAX-RS {@link DynamicFeature} which are listed as SPIs for registration. @@ -51,7 +53,8 @@ public DynamicFeatureConfigurator() { public void init(InjectionManager injectionManager, BootstrapBag bootstrapBag) { final Map properties = bootstrapBag.getConfiguration().getProperties(); if (PropertiesHelper.isJaxRsServiceLoadingEnabled(properties)) { - final List> dynamicFeatures = loadImplementations(properties); + final Set> dynamicFeatures = new HashSet<>(); + dynamicFeatures.addAll(loadImplementations(properties)); dynamicFeatures.addAll(loadImplementations(properties, DynamicFeature.class.getClassLoader())); registerFeatures(dynamicFeatures, bootstrapBag); diff --git a/core-common/src/main/java/org/glassfish/jersey/internal/FeatureConfigurator.java b/core-common/src/main/java/org/glassfish/jersey/internal/FeatureConfigurator.java index 24a24fbbb0..49854073fe 100644 --- a/core-common/src/main/java/org/glassfish/jersey/internal/FeatureConfigurator.java +++ b/core-common/src/main/java/org/glassfish/jersey/internal/FeatureConfigurator.java @@ -22,8 +22,9 @@ import javax.ws.rs.RuntimeType; import javax.ws.rs.core.Feature; -import java.util.List; +import java.util.HashSet; import java.util.Map; +import java.util.Set; /** * Registers JAX-RS {@link Feature} which are listed as SPIs for registration. @@ -44,7 +45,8 @@ public FeatureConfigurator(RuntimeType runtimeType) { public void init(InjectionManager injectionManager, BootstrapBag bootstrapBag) { final Map properties = bootstrapBag.getConfiguration().getProperties(); if (PropertiesHelper.isJaxRsServiceLoadingEnabled(properties)) { - final List> features = loadImplementations(properties); + final Set> features = new HashSet<>(); + features.addAll(loadImplementations(properties)); features.addAll(loadImplementations(properties, Feature.class.getClassLoader())); registerFeatures(features, bootstrapBag);