Skip to content

CAMEL-24573: CXF REST: UnsupportedOperationException when copying factory bean, backport to camel-4.18.x - #25970

Merged
davsclaus merged 1 commit into
camel-4.18.xfrom
backport/CAMEL-24573-4.18.x
Aug 31, 2026
Merged

CAMEL-24573: CXF REST: UnsupportedOperationException when copying factory bean, backport to camel-4.18.x#25970
davsclaus merged 1 commit into
camel-4.18.xfrom
backport/CAMEL-24573-4.18.x

Conversation

@davsclaus

Copy link
Copy Markdown
Contributor

Backport to camel-4.18.x of #25967, already reviewed and merged on main.

Problem. CxfRsSpringEndpoint.newInstanceWithCommonProperties() shallow-copies the features field from the source Spring bean. When that bean's features list is fixed-size (e.g. built with Arrays.asList()), the copy aliases the same immutable list, and a later attempt to append to it throws UnsupportedOperationException.

Fix. Wrap the copied list in a new ArrayList so 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:

  • Mechanical: 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.
  • Behavioural: on this branch, CxfRsSpringEndpoint.setupJAXRSClientFactoryBean() does not call setupCommonFactoryProperties() — that call was added later by CAMEL-24183, which is not on camel-4.18.x. So the endpoint's own features are never auto-appended to the copied list here, and the ported test's assertEquals(2, cfb.getFeatures().size()) did not hold (it failed with expected: <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-rest on this branch after adapting the test; all 4 tests in CxfRsSpringEndpointTest pass.

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

…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>
@davsclaus davsclaus added bug Something isn't working components labels Aug 31, 2026

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@davsclaus davsclaus added this to the 4.18.5 milestone Aug 31, 2026
@davsclaus
davsclaus merged commit 1270b02 into camel-4.18.x Aug 31, 2026
3 checks passed
@davsclaus
davsclaus deleted the backport/CAMEL-24573-4.18.x branch August 31, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants