This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-4.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.22.x by this push:
     new 9c2e9681fae0 CAMEL-24573: CXF REST: UnsupportedOperationException when 
copying factory bean with fixed-size features list
9c2e9681fae0 is described below

commit 9c2e9681fae0d8c3a48c834db985de6860604401
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Aug 31 19:57:19 2026 +0200

    CAMEL-24573: CXF REST: UnsupportedOperationException when copying factory 
bean with fixed-size features list
    
    Backports #25967 to camel-4.22.x, a straight cherry-pick already reviewed 
and
    merged on main. CxfRsSpringEndpoint.newInstanceWithCommonProperties()
    shallow-copies the features field from the source Spring bean; when that
    bean's features list is fixed-size (e.g. Arrays.asList()), the copy aliases
    the same immutable list, and a later addAll() call in
    setupCommonFactoryProperties() throws UnsupportedOperationException. Wraps
    the copied list in a new ArrayList so the copy is mutable, without touching
    the original Spring bean's list.
    
    Co-authored-by: Claude Haiku 4.5 <[email protected]>
    
    Closes #25969
---
 .../cxf/spring/jaxrs/CxfRsSpringEndpoint.java      |  3 +++
 .../cxf/jaxrs/CxfRsSpringEndpointTest.java         | 25 ++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git 
a/components/camel-cxf/camel-cxf-spring-rest/src/main/java/org/apache/camel/component/cxf/spring/jaxrs/CxfRsSpringEndpoint.java
 
b/components/camel-cxf/camel-cxf-spring-rest/src/main/java/org/apache/camel/component/cxf/spring/jaxrs/CxfRsSpringEndpoint.java
index a2f564abff43..83ad90afb3de 100644
--- 
a/components/camel-cxf/camel-cxf-spring-rest/src/main/java/org/apache/camel/component/cxf/spring/jaxrs/CxfRsSpringEndpoint.java
+++ 
b/components/camel-cxf/camel-cxf-spring-rest/src/main/java/org/apache/camel/component/cxf/spring/jaxrs/CxfRsSpringEndpoint.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.cxf.spring.jaxrs;
 
+import java.util.ArrayList;
+
 import org.apache.camel.Component;
 import org.apache.camel.component.cxf.jaxrs.BeanIdAware;
 import org.apache.camel.component.cxf.jaxrs.CxfRsEndpoint;
@@ -110,6 +112,7 @@ public class CxfRsSpringEndpoint extends CxfRsEndpoint 
implements BeanIdAware {
 
         if (bean instanceof SpringJAXRSClientFactoryBean) {
             ReflectionUtils.shallowCopyFieldState(bean, cfb);
+            cfb.setFeatures(new ArrayList<>(cfb.getFeatures()));
         }
 
         return cfb;
diff --git 
a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointTest.java
 
b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointTest.java
index 9fc1d967786c..3bbefade6ada 100644
--- 
a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointTest.java
+++ 
b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointTest.java
@@ -16,12 +16,14 @@
  */
 package org.apache.camel.component.cxf.jaxrs;
 
+import java.util.Arrays;
 import java.util.Map;
 
 import org.apache.camel.component.cxf.jaxrs.testbean.CustomerService;
 import 
org.apache.camel.component.cxf.spring.jaxrs.SpringJAXRSClientFactoryBean;
 import 
org.apache.camel.component.cxf.spring.jaxrs.SpringJAXRSServerFactoryBean;
 import org.apache.camel.test.spring.junit6.CamelSpringTestSupport;
+import org.apache.cxf.feature.AbstractFeature;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -36,6 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 public class CxfRsSpringEndpointTest extends CamelSpringTestSupport {
 
     private static final String BEAN_SERVICE_ENDPOINT_NAME = "serviceEndpoint";
+    private static final String FIXED_SIZE_FEATURES_ENDPOINT_NAME = 
"fixedSizeFeaturesEndpoint";
     private static final String BEAN_SERVICE_ADDRESS = 
"http://localhost/programmatically";;
     private static final String BEAN_SERVICE_USERNAME = 
"BEAN_SERVICE_USERNAME";
     private static final String BEAN_SERVICE_PASSWORD = 
"BEAN_SERVICE_PASSWORD";
@@ -88,6 +91,16 @@ public class CxfRsSpringEndpointTest extends 
CamelSpringTestSupport {
         assertEquals(BEAN_SERVICE_PASSWORD, cfb.getPassword(), "Got the wrong 
password");
     }
 
+    @Test
+    public void testCreateCxfRsClientFactoryBeanWithFixedSizeFeatures() {
+        CxfRsEndpoint endpoint = resolveMandatoryEndpoint(
+                "cxfrs://bean://" + FIXED_SIZE_FEATURES_ENDPOINT_NAME, 
CxfRsEndpoint.class);
+
+        SpringJAXRSClientFactoryBean cfb = (SpringJAXRSClientFactoryBean) 
endpoint.createJAXRSClientFactoryBean();
+
+        assertEquals(2, cfb.getFeatures().size(), "The endpoint features must 
be appended to the copied feature list");
+    }
+
     public static SpringJAXRSClientFactoryBean serviceEndpoint() {
 
         SpringJAXRSClientFactoryBean clientFactoryBean = new 
SpringJAXRSClientFactoryBean();
@@ -99,6 +112,13 @@ public class CxfRsSpringEndpointTest extends 
CamelSpringTestSupport {
         return clientFactoryBean;
     }
 
+    public static SpringJAXRSClientFactoryBean fixedSizeFeaturesEndpoint() {
+        SpringJAXRSClientFactoryBean clientFactoryBean = serviceEndpoint();
+        clientFactoryBean.setFeatures(Arrays.asList(new AbstractFeature() {
+        }));
+        return clientFactoryBean;
+    }
+
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
 
@@ -115,5 +135,10 @@ public class CxfRsSpringEndpointTest extends 
CamelSpringTestSupport {
         BeanDefinitionBuilder definitionBuilder = BeanDefinitionBuilder
                 
.rootBeanDefinition(CxfRsSpringEndpointTest.class.getName()).setFactoryMethod("serviceEndpoint");
         beanFactory.registerBeanDefinition(BEAN_SERVICE_ENDPOINT_NAME, 
definitionBuilder.getBeanDefinition());
+
+        BeanDefinitionBuilder fixedSizeFeaturesDefinitionBuilder = 
BeanDefinitionBuilder
+                
.rootBeanDefinition(CxfRsSpringEndpointTest.class.getName()).setFactoryMethod("fixedSizeFeaturesEndpoint");
+        beanFactory.registerBeanDefinition(FIXED_SIZE_FEATURES_ENDPOINT_NAME,
+                fixedSizeFeaturesDefinitionBuilder.getBeanDefinition());
     }
 }

Reply via email to