(chores): fix SonarCloud S2975 clone without super.clone#24487
Draft
gnodet wants to merge 1 commit into
Draft
Conversation
Fix 3 clone() methods that don't call super.clone(), addressing SonarCloud rule java:S2975. - MiloClientConfiguration: use super.clone() with deep copy of mutable allowedSecurityPolicies set - ThreadPoolProfile: use super.clone() (all fields are immutable primitives/wrappers/enums/String) - DefaultLineBuilderStrategy.LineBuilder: rename clone() to copy() since the private inner class doesn't implement Cloneable Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
davsclaus
approved these changes
Jul 7, 2026
Contributor
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 552 tested, 29 compile-only — current: 552 all testedMaveniverse Scalpel detected 581 affected modules (current approach: 552).
|
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.
Summary
Fix 3
clone()methods that don't callsuper.clone(), addressing SonarCloud rule java:S2975.Why SonarCloud flags these
SonarCloud rule S2975 ("clone should not be overridden") fires on any override of
clone(). The rationale (from Joshua Bloch's Effective Java) is thatObject.clone()has a fundamentally broken contract:super.clone()only creates a shallow copy — mutable fields are shared between original and clone, so mutating one silently corrupts the other.Object.clone()creates objects without calling any constructor, violating the invariant that all objects should be built through constructors.newinstead ofsuper.clone(), subclass clones get the wrong runtime type.The 3 files fixed here had the most concrete violation — they didn't call
super.clone()at all, usingnewinstead.Changes
MiloClientConfigurationclone()usednew MiloClientConfiguration(this)— breaks subclass cloning and theCloneablecontractsuper.clone()+ deep-copy of mutableallowedSecurityPoliciesHashSetThreadPoolProfileclone()usednew ThreadPoolProfile()+ manual field-by-field copy — same subclass problem, plus was already missing thesessionTimeoutfieldsuper.clone()(all fields are immutable primitives/wrappers/enums/String)DefaultLineBuilderStrategy.LineBuilderclone()usednew LineBuilder(...)— overridesObject.clone()without implementingCloneableclone()tocopy()since this private inner class doesn't needCloneableNote on the remaining 7 SonarCloud S2975 issues
The remaining 7 flagged files (
Transcribe2Configuration, 5× Infinispan configs,ComponentModel.ApiOptionModel) already callsuper.clone()correctly. SonarCloud still flags them because S2975 fires on anyclone()override — its position is thatclone()shouldn't be used at all. However, these areCloneableconfiguration classes used throughout Camel's component framework for endpoint creation. Removingclone()would be a breaking API change with no functional benefit, since they already follow thesuper.clone()contract correctly.Test plan
mvn testpasses incore/camel-apimvn testpasses incomponents/camel-milo(43 tests, 0 failures)mvn testpasses incomponents/camel-pdf(10 tests, 0 failures)mvn formatter:format impsort:sortapplied on all 3 modulescamel-vertx-websocket(flaky test), not in any changed moduleClaude Code on behalf of gnodet
🤖 Generated with Claude Code