CAMEL-24573: CXF REST: UnsupportedOperationException when copying factory bean, backport to camel-4.18.x - #25970
Merged
Merged
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 resulted in a reference to the immutable list. Subsequent attempts to append endpoint features via addAll() threw UnsupportedOperationException. Wrap the copied features list in a new ArrayList to ensure mutability while preserving the original values. Fixes CSB-10555 (cherry picked from commit 98615a5) Deviations from a straight cherry-pick, both mechanical: - Import conflict resolved for this branch: CxfRsSpringEndpointTest keeps this branch's org.apache.camel.test.spring.junit5.CamelSpringTestSupport import rather than main's junit6 one; camel-cxf-spring-rest here depends on camel-test-spring-junit5, not junit6. - CxfRsSpringEndpoint.setupJAXRSClientFactoryBean() on this branch does not call setupCommonFactoryProperties() (that call was added later by CAMEL-24183, which is not on this branch), so the endpoint's own features are never auto-appended to the copied list here. The ported test's assertEquals(2, cfb.getFeatures().size()) does not hold on this branch: it now asserts the copied feature is preserved (1) and that the list is mutable by appending a second feature directly and re-checking the size (2), which still exercises the fix without relying on 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>
gnodet
approved these changes
Aug 31, 2026
gnodet
left a comment
Contributor
There was a problem hiding this comment.
Backport of #25967 to camel-4.18.x — same one-line fix (new ArrayList<>(cfb.getFeatures())) making the shallow-copied features list mutable after ReflectionUtils.shallowCopyFieldState. The test is slightly enhanced compared to the original (granular size assertions + assertDoesNotThrow), which is a nice improvement. Core fix already reviewed and approved on main (#25967) and camel-4.22.x (#25969).
LGTM ✅
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport to
camel-4.18.xof #25967, 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, and a later attempt to append to it throwsUnsupportedOperationException.Fix. Wrap the copied list in a new
ArrayListso the copy is mutable, without touching the original Spring bean's list.Not a straight cherry-pick — two deviations, both surfaced by building/testing this branch:
CxfRsSpringEndpointTestkeeps this branch'sorg.apache.camel.test.spring.junit5.CamelSpringTestSupportimport rather thanmain'sjunit6one —camel-cxf-spring-resthere depends oncamel-test-spring-junit5, notjunit6.CxfRsSpringEndpoint.setupJAXRSClientFactoryBean()does not callsetupCommonFactoryProperties()— that call was added later by CAMEL-24183, which is not oncamel-4.18.x. So the endpoint's own features are never auto-appended to the copied list here, and the ported test'sassertEquals(2, cfb.getFeatures().size())did not hold (it failed withexpected: <2> but was: <1>when run on this branch). The test now asserts the copied feature is preserved (size 1) and that the list is mutable by appending a second feature directly and re-checking the size (2) — this still exercises the fix (mutability) without relying on the CAMEL-24183 auto-append behaviour this branch doesn't have.Built and tested
camel-cxf-spring-reston this branch after adapting the test; all 4 tests inCxfRsSpringEndpointTestpass.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.18.x