This is an automated email from the ASF dual-hosted git repository. reta pushed a commit to branch 3.6.x-fixes in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 2458aa216c340a730ad21abd0e21bb431533c8de Author: Romain Manni-Bucau <[email protected]> AuthorDate: Tue Apr 9 17:43:42 2024 +0200 [cdi] semuru does not have a native Object.hashCode so OWB proxies hashCode (request scoped for ex) and hashset triggering a hashCode in CDI extension it can fail since there is no request scope there by default (#1794) (cherry picked from commit d94f8f6c5efd1ea26b11d01c979a0d1af79bf1b8) --- .../apache/cxf/cdi/JAXRSCdiResourceExtension.java | 27 +++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java b/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java index 42dada4b72..5016f25656 100644 --- a/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java +++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java @@ -82,15 +82,16 @@ public class JAXRSCdiResourceExtension implements Extension { private boolean hasBus; private Bus bus; - private final Set< Bean< ? > > applicationBeans = new LinkedHashSet< Bean< ? > >(); - private final List< Bean< ? > > serviceBeans = new ArrayList< Bean< ? > >(); - private final List< Bean< ? > > providerBeans = new ArrayList< Bean< ? > >(); - private final List< Bean< ? extends Feature > > featureBeans = new ArrayList< Bean< ? extends Feature > >(); + private Set< Bean< ? > > applicationBeans = new LinkedHashSet< Bean< ? > >(); + private Set< Bean< ? > > serviceBeans = new HashSet< Bean< ? > >(); + private Set< Bean< ? > > providerBeans = new HashSet< Bean< ? > >(); + private Set< Bean< ? extends Feature > > featureBeans = new HashSet< Bean< ? extends Feature > >(); + private Set< Type > contextTypes = new LinkedHashSet<>(); + private final List< CreationalContext< ? > > disposableCreationalContexts = new ArrayList<>(); private final List< Lifecycle > disposableLifecycles = new ArrayList<>(); - private final Set< Type > contextTypes = new LinkedHashSet<>(); private final Collection< String > existingStandardClasses = new HashSet<>(); @@ -262,6 +263,8 @@ public class JAXRSCdiResourceExtension implements Extension { factory.init(); } } + + cleanStartupData(); } public void injectBus(@Observes final AfterBeanDiscovery event, final BeanManager beanManager) { @@ -295,6 +298,15 @@ public class JAXRSCdiResourceExtension implements Extension { t -> event.addBean(new ContextProducerBean(t, !existingStandardClasses.contains(t.getTypeName())))); } + private void cleanStartupData() { // enable gc + Stream.of(serviceBeans, providerBeans, featureBeans, applicationBeans, contextTypes).forEach(Collection::clear); + serviceBeans = null; + providerBeans = null; + featureBeans = null; + applicationBeans = null; + contextTypes = null; + } + /** * Registers created CreationalContext instances for disposal */ @@ -473,8 +485,7 @@ public class JAXRSCdiResourceExtension implements Extension { */ private List< Object > loadBeans(final BeanManager beanManager, Collection<Class<?>> limitedClasses, Collection<Bean<?>> beans) { - // Use set to account for singletons and application scoped beans - final Set< Object > instances = new LinkedHashSet<>(); + final List< Object > instances = new ArrayList<>(); for (final Bean< ? > bean: beans) { if (limitedClasses.isEmpty() || limitedClasses.contains(bean.getBeanClass())) { @@ -488,7 +499,7 @@ public class JAXRSCdiResourceExtension implements Extension { } } - return new ArrayList<>(instances); + return instances; } /**
