This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new aa81b40aec11 (chores): fix SonarCloud S2975 clone without super.clone
aa81b40aec11 is described below
commit aa81b40aec11d31c6bc955a1a8248f1976f1fc54
Author: Guillaume Nodet <[email protected]>
AuthorDate: Wed Jul 8 07:12:20 2026 +0200
(chores): fix SonarCloud S2975 clone without super.clone
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() since all fields are immutable. DefaultLineBuilderStrategy
LineBuilder: rename clone() to copy() since the private inner class doesn't
implement Cloneable.
Closes #24487
Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
.../component/milo/client/MiloClientConfiguration.java | 9 ++++++++-
.../component/pdf/text/DefaultLineBuilderStrategy.java | 5 ++---
.../java/org/apache/camel/spi/ThreadPoolProfile.java | 17 ++++++-----------
3 files changed, 16 insertions(+), 15 deletions(-)
diff --git
a/components/camel-milo/src/main/java/org/apache/camel/component/milo/client/MiloClientConfiguration.java
b/components/camel-milo/src/main/java/org/apache/camel/component/milo/client/MiloClientConfiguration.java
index 56d1534f0e73..6859b9fd896a 100644
---
a/components/camel-milo/src/main/java/org/apache/camel/component/milo/client/MiloClientConfiguration.java
+++
b/components/camel-milo/src/main/java/org/apache/camel/component/milo/client/MiloClientConfiguration.java
@@ -453,7 +453,14 @@ public class MiloClientConfiguration implements Cloneable {
@Override
public MiloClientConfiguration clone() {
- return new MiloClientConfiguration(this);
+ try {
+ MiloClientConfiguration copy = (MiloClientConfiguration)
super.clone();
+ copy.allowedSecurityPolicies
+ = this.allowedSecurityPolicies != null ? new
HashSet<>(this.allowedSecurityPolicies) : null;
+ return copy;
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeCamelException(e);
+ }
}
public String toCacheId() {
diff --git
a/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/text/DefaultLineBuilderStrategy.java
b/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/text/DefaultLineBuilderStrategy.java
index 5d39efe82da1..3bec47adc52f 100644
---
a/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/text/DefaultLineBuilderStrategy.java
+++
b/components/camel-pdf/src/main/java/org/apache/camel/component/pdf/text/DefaultLineBuilderStrategy.java
@@ -101,7 +101,7 @@ public class DefaultLineBuilderStrategy implements
LineBuilderStrategy {
}
private boolean isWordFitInCurrentLine(LineBuilder currentLine, String
word, float allowedLineWidth) throws IOException {
- LineBuilder lineBuilder = currentLine.clone().appendWord(word);
+ LineBuilder lineBuilder = currentLine.copy().appendWord(word);
return isLineFitInLineWidth(lineBuilder.buildLine(), allowedLineWidth);
}
@@ -160,8 +160,7 @@ public class DefaultLineBuilderStrategy implements
LineBuilderStrategy {
wordsCount = 0;
}
- @Override
- public LineBuilder clone() {
+ public LineBuilder copy() {
return new LineBuilder(this.line.toString(), this.wordsCount);
}
diff --git
a/core/camel-api/src/main/java/org/apache/camel/spi/ThreadPoolProfile.java
b/core/camel-api/src/main/java/org/apache/camel/spi/ThreadPoolProfile.java
index a5038c0d5b2c..7ccb224f17ce 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/ThreadPoolProfile.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/ThreadPoolProfile.java
@@ -22,6 +22,7 @@ import java.util.Objects;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.TimeUnit;
+import org.apache.camel.RuntimeCamelException;
import org.apache.camel.util.concurrent.ThreadPoolRejectedPolicy;
import org.jspecify.annotations.Nullable;
@@ -289,17 +290,11 @@ public class ThreadPoolProfile implements Serializable,
Cloneable {
@Override
public ThreadPoolProfile clone() {
- ThreadPoolProfile cloned = new ThreadPoolProfile();
- cloned.setDefaultProfile(defaultProfile);
- cloned.setId(id);
- cloned.setKeepAliveTime(keepAliveTime);
- cloned.setMaxPoolSize(maxPoolSize);
- cloned.setMaxQueueSize(maxQueueSize);
- cloned.setPoolSize(poolSize);
- cloned.setAllowCoreThreadTimeOut(allowCoreThreadTimeOut);
- cloned.setRejectedPolicy(rejectedPolicy);
- cloned.setTimeUnit(timeUnit);
- return cloned;
+ try {
+ return (ThreadPoolProfile) super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeCamelException(e);
+ }
}
@Override