CAMEL-24573: CXF REST: UnsupportedOperationException when copying factory bean, backport to camel-4.22.x - #25969
Conversation
…tory bean with fixed-size features list When creating a CXF JAXRS client factory bean from a Spring bean with a fixed-size features list (e.g., from Arrays.asList()), the shallow field copy in CxfRsSpringEndpoint.newInstanceWithCommonProperties() resulted in a reference to the immutable list. A subsequent attempt to append endpoint features via addAll() in setupCommonFactoryProperties() then threw UnsupportedOperationException. Wrap the copied features list in a new ArrayList so the copy is mutable, while leaving the original Spring bean's list untouched. Adds testCreateCxfRsClientFactoryBeanWithFixedSizeFeatures to cover the fixed-size-list case. Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com> Closes #25967
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 9 tested, 29 compile-only — current: 9 all testedMaveniverse Scalpel detected 38 affected modules (current approach: 9).
|
gnodet
left a comment
There was a problem hiding this comment.
Straight cherry-pick backport of #25967 to camel-4.22.x. The original PR was already reviewed — the fix correctly wraps the shallow-copied features list in a new ArrayList to prevent UnsupportedOperationException when setupCommonFactoryProperties() calls addAll() on a fixed-size list.
No manual adaptation needed. Test included.
📋 PR Metadata
| Aspect | Current | Suggested |
|---|---|---|
| Milestone | (none) | 4.22.1 |
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
…tory bean, backport to camel-4.18.x Backports #25967 to camel-4.18.x. Same fix as #25969: wraps the shallow-copied features field in a new ArrayList in CxfRsSpringEndpoint.newInstanceWithCommonProperties() so a fixed-size source list (e.g. Arrays.asList()) doesn't cause UnsupportedOperationException on a later append. Not a straight cherry-pick: this branch's camel-cxf-spring-rest test module depends on camel-test-spring-junit5, not junit6, so the test's import was kept as-is. More substantially, CxfRsSpringEndpoint.setupJAXRSClientFactoryBean() on this branch never calls setupCommonFactoryProperties() (that call was added later by CAMEL-24183, not present here), so the endpoint's own features are never auto-appended to the copied list. The ported test is adapted to assert the copied feature is preserved and that the list is mutable by appending directly, rather than relying on auto-append behaviour this branch doesn't have. Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Closes #25970
Backport to
camel-4.22.xof #25967, a straight cherry-pick already reviewed and merged onmain.featureslist (CAMEL-24573: CXF REST: UnsupportedOperationException when copying fac… #25967,98615a5d)Problem.
CxfRsSpringEndpoint.newInstanceWithCommonProperties()shallow-copies thefeaturesfield from the source Spring bean. When that bean'sfeatureslist is fixed-size (e.g. built withArrays.asList()), the copy aliases the same immutable list. A lateraddAll()call insetupCommonFactoryProperties()then throwsUnsupportedOperationException.Fix. Wrap the copied list in a new
ArrayListso the copy is mutable, without touching the original Spring bean's list.Straight cherry-pick of the squash-merge commit, no manual adaptation needed. Built and tested
camel-cxf-spring-reston this branch, including the newtestCreateCxfRsClientFactoryBeanWithFixedSizeFeatures.Claude Code on behalf of davsclaus
Backport of #25967
Original PR: #25967 - CAMEL-24573: CXF REST: UnsupportedOperationException when copying factory bean with fixed-size features list
Original author: @mcarlett
Target branch:
camel-4.22.x