You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2026/02/10 12:49:13 UTC

(camel) branch main updated (a503e3912177 -> 925957d65c6c)

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


    from a503e3912177 CAMEL-22975 - Camel-jbang-MCP: Add Kamelets catalog and doc tool (#21382)
     new fecd459e6d71 (chores): modernize instanceof checks in camel-support
     new fa47be2bdf2d (chores): modernize instanceof checks in camel-management
     new a0a35006eb64 (chores): modernize instanceof checks in camel-telemetry
     new 6bbd89a6243d (chores): modernize instanceof checks in camel-minio
     new 15c805c26d28 (chores): modernize instanceof checks in camel-keycloak
     new bbdc5df2d286 (chores): modernize instanceof checks in camel-datasonnet
     new 925957d65c6c (chores): modernize instanceof checks in camel-aws2-s3

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/component/aws2/s3/AWS2S3Producer.java    |  29 ++-
 .../org/apache/camel/language/datasonnet/CML.java  |  12 +-
 .../keycloak/security/KeycloakSecurityHelper.java  |  52 ++---
 .../camel/component/minio/MinioProducer.java       |   4 +-
 .../decorators/AbstractHttpSpanDecorator.java      |   4 +-
 .../DefaultManagementObjectStrategy.java           | 244 ++++++++++-----------
 .../org/apache/camel/support/LoggerHelper.java     |  15 +-
 .../org/apache/camel/support/ObjectHelper.java     |  55 +++--
 8 files changed, 202 insertions(+), 213 deletions(-)


(camel) 04/07: (chores): modernize instanceof checks in camel-minio

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 6bbd89a6243d5257d6d6afc2732c16402005afb2
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Feb 10 08:36:08 2026 +0000

    (chores): modernize instanceof checks in camel-minio
---
 .../src/main/java/org/apache/camel/component/minio/MinioProducer.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java b/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java
index dc870adf4dc2..0daf1cdb73c4 100644
--- a/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java
+++ b/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java
@@ -156,8 +156,8 @@ public class MinioProducer extends DefaultProducer {
                 if (object == null) {
                     throw new IllegalArgumentException("Message body is null");
                 }
-                if (object instanceof File) {
-                    filePayload = (File) object;
+                if (object instanceof File file) {
+                    filePayload = file;
                     inputStream = new FileInputStream(filePayload);
                     if (contentLength <= 0) {
                         contentLength = filePayload.length();


(camel) 01/07: (chores): modernize instanceof checks in camel-support

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit fecd459e6d71ad6c3169633ae2f53868cdab5c7f
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Feb 10 08:27:49 2026 +0000

    (chores): modernize instanceof checks in camel-support
---
 .../org/apache/camel/support/LoggerHelper.java     | 15 +++---
 .../org/apache/camel/support/ObjectHelper.java     | 55 ++++++++++------------
 2 files changed, 32 insertions(+), 38 deletions(-)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/LoggerHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/LoggerHelper.java
index a167ba8dea85..1cf3e282a892 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/LoggerHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/LoggerHelper.java
@@ -38,13 +38,12 @@ public final class LoggerHelper {
      */
     public static String getLineNumberLoggerName(Object node) {
         String name = null;
-        if (node instanceof LineNumberAware) {
+        if (node instanceof LineNumberAware lineNumberAware) {
             if (node instanceof NamedRoute namedRoute) {
                 // we want the input from a route as it has the source location / line number
-                node = namedRoute.getInput();
+                lineNumberAware = (LineNumberAware) namedRoute.getInput();
             }
 
-            final LineNumberAware lineNumberAware = (LineNumberAware) node;
             String loc = lineNumberAware.getLocation();
             int line = lineNumberAware.getLineNumber();
             if (loc != null) {
@@ -73,13 +72,12 @@ public final class LoggerHelper {
 
     public static String getSourceLocation(Object node) {
         String name = null;
-        if (node instanceof LineNumberAware) {
+        if (node instanceof LineNumberAware lineNumberAware) {
             if (node instanceof NamedRoute namedRoute) {
                 // we want the input from a route as it has the source location / line number
-                node = namedRoute.getInput();
+                lineNumberAware = (LineNumberAware) namedRoute.getInput();
             }
 
-            final LineNumberAware lineNumberAware = (LineNumberAware) node;
             String loc = lineNumberAware.getLocation();
             int line = lineNumberAware.getLineNumber();
             if (loc != null) {
@@ -95,9 +93,8 @@ public final class LoggerHelper {
 
     public static String getSourceLocationOnly(Object node) {
         String name = null;
-        if (node instanceof LineNumberAware lna) {
-            LineNumberAware lineNumberAware = lna;
-            if (lna instanceof NamedRoute namedRoute) {
+        if (node instanceof LineNumberAware lineNumberAware) {
+            if (node instanceof NamedRoute namedRoute) {
                 // we want the input from a route as it has the source location / line number
                 lineNumberAware = (LineNumberAware) namedRoute.getInput();
             }
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java
index a5acef72f256..df24b780a78b 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java
@@ -217,19 +217,21 @@ public final class ObjectHelper {
     }
 
     private static boolean typeCoerceIntLong(Object leftValue, String rightValue) {
-        if (leftValue instanceof Integer) {
-            return integerPairComparison((Integer) leftValue, Integer.valueOf(rightValue));
-        } else {
-            return longPairComparison((Long) leftValue, Long.valueOf(rightValue));
+        if (leftValue instanceof Integer intValue) {
+            return integerPairComparison(intValue, Integer.valueOf(rightValue));
+        } else if (leftValue instanceof Long longValue) {
+            return longPairComparison(longValue, Long.valueOf(rightValue));
         }
+        return false;
     }
 
     private static boolean typeCoerceILString(String leftValue, Object rightValue) {
-        if (rightValue instanceof Integer) {
-            return integerPairComparison(Integer.valueOf(leftValue), (Integer) rightValue);
-        } else {
-            return longPairComparison(Long.valueOf(leftValue), (Long) rightValue);
+        if (rightValue instanceof Integer intValue) {
+            return integerPairComparison(Integer.valueOf(leftValue), intValue);
+        } else if (rightValue instanceof Long longValue) {
+            return longPairComparison(Long.valueOf(leftValue), longValue);
         }
+        return false;
     }
 
     private static boolean typeCoerceStringPair(String leftNum, String rightNum, boolean ignoreCase) {
@@ -282,14 +284,13 @@ public final class ObjectHelper {
                 Long rightNum = (Long) rightValue;
                 return leftNum.compareTo(rightNum);
             }
-        } else if (rightValue instanceof String &&
-                (leftValue instanceof Integer || leftValue instanceof Long) && isNumber((String) rightValue)) {
+        } else if (rightValue instanceof String rightStr &&
+                (leftValue instanceof Integer || leftValue instanceof Long) && isNumber(rightStr)) {
             if (leftValue instanceof Integer leftNum) {
-                Integer rightNum = Integer.valueOf((String) rightValue);
+                Integer rightNum = Integer.valueOf(rightStr);
                 return leftNum.compareTo(rightNum);
-            } else {
-                Long leftNum = (Long) leftValue;
-                Long rightNum = Long.valueOf((String) rightValue);
+            } else if (leftValue instanceof Long leftNum) {
+                Long rightNum = Long.valueOf(rightStr);
                 return leftNum.compareTo(rightNum);
             }
         } else if (rightValue instanceof Double rightNum && leftValue instanceof String leftStr
@@ -300,11 +301,11 @@ public final class ObjectHelper {
                 && isFloatingNumber(leftStr)) {
             Float leftNum = Float.valueOf(leftStr);
             return leftNum.compareTo(rightNum);
-        } else if (rightValue instanceof Boolean rightBool && leftValue instanceof String) {
-            Boolean leftBool = Boolean.valueOf((String) leftValue);
+        } else if (rightValue instanceof Boolean rightBool && leftValue instanceof String leftStr) {
+            Boolean leftBool = Boolean.valueOf(leftStr);
             return leftBool.compareTo(rightBool);
-        } else if (rightValue instanceof String && leftValue instanceof Boolean leftBool) {
-            Boolean rightBool = Boolean.valueOf((String) rightValue);
+        } else if (rightValue instanceof String rightStr && leftValue instanceof Boolean leftBool) {
+            Boolean rightBool = Boolean.valueOf(rightStr);
             return leftBool.compareTo(rightBool);
         }
 
@@ -845,17 +846,14 @@ public final class ObjectHelper {
 
     @SuppressWarnings("unchecked")
     private static Iterable<?> trySlowIterables(Object value) {
-        if (value instanceof Iterator) {
-            final Iterator<Object> iterator = (Iterator<Object>) value;
-            return (Iterable<Object>) () -> iterator;
-        } else if (value instanceof Iterable) {
-            return (Iterable<Object>) value;
-        } else if (value instanceof Map) {
-            Map<?, ?> map = (Map<?, ?>) value;
+        if (value instanceof Iterator<?> iterator) {
+            return (Iterable<Object>) () -> (Iterator<Object>) iterator;
+        } else if (value instanceof Iterable<?> iterable) {
+            return (Iterable<Object>) iterable;
+        } else if (value instanceof Map<?, ?> map) {
             return map.entrySet();
-        } else if (value instanceof NodeList) {
+        } else if (value instanceof NodeList nodeList) {
             // lets iterate through DOM results after performing XPaths
-            final NodeList nodeList = (NodeList) value;
             return (Iterable<Node>) () -> createNodeListIterator(nodeList);
         } else {
             return Collections.singletonList(value);
@@ -1030,8 +1028,7 @@ public final class ObjectHelper {
         if (collectionOrArray instanceof byte[] arr) {
             collectionOrArray = new String(arr);
         }
-        if (collectionOrArray instanceof Collection) {
-            Collection<?> collection = (Collection<?>) collectionOrArray;
+        if (collectionOrArray instanceof Collection<?> collection) {
             if (ignoreCase) {
                 String lower = value.toString().toLowerCase(Locale.ENGLISH);
                 return collection.stream().anyMatch(c -> c.toString().toLowerCase(Locale.ENGLISH).contains(lower));


(camel) 03/07: (chores): modernize instanceof checks in camel-telemetry

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit a0a35006eb64f4fc37ee9c777bad123467dea1d3
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Feb 10 08:33:38 2026 +0000

    (chores): modernize instanceof checks in camel-telemetry
---
 .../apache/camel/telemetry/decorators/AbstractHttpSpanDecorator.java  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AbstractHttpSpanDecorator.java b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AbstractHttpSpanDecorator.java
index 8bfdd8ac785f..e0ae5b91a376 100644
--- a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AbstractHttpSpanDecorator.java
+++ b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AbstractHttpSpanDecorator.java
@@ -32,8 +32,8 @@ public abstract class AbstractHttpSpanDecorator extends AbstractSpanDecorator {
         Object method = exchange.getIn().getHeader(Exchange.HTTP_METHOD);
         if (method instanceof String str) {
             return str;
-        } else if (method instanceof Enum) {
-            return ((Enum<?>) method).name();
+        } else if (method instanceof Enum<?> enumValue) {
+            return enumValue.name();
         } else if (method != null) {
             return exchange.getContext().getTypeConverter().tryConvertTo(String.class, exchange, method);
         }


(camel) 07/07: (chores): modernize instanceof checks in camel-aws2-s3

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 925957d65c6cf1a8f693f066f19f43f8a022d9ab
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Feb 10 08:43:54 2026 +0000

    (chores): modernize instanceof checks in camel-aws2-s3
---
 .../camel/component/aws2/s3/AWS2S3Producer.java    | 29 +++++++++++-----------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
index 4b24bb1900ff..01eb91ac8d26 100644
--- a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
+++ b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
@@ -332,9 +332,9 @@ public class AWS2S3Producer extends DefaultProducer {
                 contentLength = wrappedFile.getFileLength();
                 obj = wrappedFile.getFile();
             }
-            if (obj instanceof File) {
+            if (obj instanceof File file) {
                 // optimize for file payload
-                filePayload = (File) obj;
+                filePayload = file;
                 contentLength = filePayload.length();
             } else {
                 // okay we use input stream
@@ -478,9 +478,8 @@ public class AWS2S3Producer extends DefaultProducer {
         final String bucketNameDestination = exchange.getIn().getHeader(AWS2S3Constants.BUCKET_DESTINATION_NAME, String.class);
         if (getConfiguration().isPojoRequest()) {
             Object payload = exchange.getIn().getMandatoryBody();
-            if (payload instanceof CopyObjectRequest) {
-                CopyObjectResponse result;
-                result = s3Client.copyObject((CopyObjectRequest) payload);
+            if (payload instanceof CopyObjectRequest req) {
+                CopyObjectResponse result = s3Client.copyObject(req);
                 Message message = getMessageForResponse(exchange);
                 message.setBody(result);
             }
@@ -553,8 +552,8 @@ public class AWS2S3Producer extends DefaultProducer {
 
         if (getConfiguration().isPojoRequest()) {
             Object payload = exchange.getIn().getMandatoryBody();
-            if (payload instanceof DeleteObjectRequest) {
-                s3Client.deleteObject((DeleteObjectRequest) payload);
+            if (payload instanceof DeleteObjectRequest req) {
+                s3Client.deleteObject(req);
                 Message message = getMessageForResponse(exchange);
                 message.setBody(true);
             }
@@ -581,8 +580,8 @@ public class AWS2S3Producer extends DefaultProducer {
 
         if (getConfiguration().isPojoRequest()) {
             Object payload = exchange.getIn().getMandatoryBody();
-            if (payload instanceof DeleteBucketRequest) {
-                DeleteBucketResponse resp = s3Client.deleteBucket((DeleteBucketRequest) payload);
+            if (payload instanceof DeleteBucketRequest req) {
+                DeleteBucketResponse resp = s3Client.deleteBucket(req);
                 Message message = getMessageForResponse(exchange);
                 message.setBody(resp);
             }
@@ -598,9 +597,9 @@ public class AWS2S3Producer extends DefaultProducer {
     private void getObject(S3Client s3Client, Exchange exchange) throws InvalidPayloadException {
         if (getConfiguration().isPojoRequest()) {
             Object payload = exchange.getIn().getMandatoryBody();
-            if (payload instanceof GetObjectRequest) {
+            if (payload instanceof GetObjectRequest req) {
                 ResponseInputStream<GetObjectResponse> res
-                        = s3Client.getObject((GetObjectRequest) payload, ResponseTransformer.toInputStream());
+                        = s3Client.getObject(req, ResponseTransformer.toInputStream());
                 Message message = getMessageForResponse(exchange);
                 if (!getConfiguration().isIgnoreBody()) {
                     message.setBody(res);
@@ -650,9 +649,9 @@ public class AWS2S3Producer extends DefaultProducer {
 
         if (getConfiguration().isPojoRequest()) {
             Object payload = exchange.getIn().getMandatoryBody();
-            if (payload instanceof GetObjectRequest) {
+            if (payload instanceof GetObjectRequest req) {
                 ResponseInputStream<GetObjectResponse> res
-                        = s3Client.getObject((GetObjectRequest) payload, ResponseTransformer.toInputStream());
+                        = s3Client.getObject(req, ResponseTransformer.toInputStream());
                 Message message = getMessageForResponse(exchange);
                 message.setBody(res);
             }
@@ -678,8 +677,8 @@ public class AWS2S3Producer extends DefaultProducer {
 
         if (getConfiguration().isPojoRequest()) {
             Object payload = exchange.getIn().getMandatoryBody();
-            if (payload instanceof ListObjectsRequest) {
-                ListObjectsResponse objectList = s3Client.listObjects((ListObjectsRequest) payload);
+            if (payload instanceof ListObjectsRequest req) {
+                ListObjectsResponse objectList = s3Client.listObjects(req);
                 Message message = getMessageForResponse(exchange);
                 message.setBody(objectList.contents());
             }


(camel) 05/07: (chores): modernize instanceof checks in camel-keycloak

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 15c805c26d28b6427126cfe21853f952a1a8898e
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Feb 10 08:40:15 2026 +0000

    (chores): modernize instanceof checks in camel-keycloak
---
 .../keycloak/security/KeycloakSecurityHelper.java  | 52 +++++++++++-----------
 1 file changed, 27 insertions(+), 25 deletions(-)

diff --git a/components/camel-keycloak/src/main/java/org/apache/camel/component/keycloak/security/KeycloakSecurityHelper.java b/components/camel-keycloak/src/main/java/org/apache/camel/component/keycloak/security/KeycloakSecurityHelper.java
index 9ef6a9d6f5ab..30967fbeed7c 100644
--- a/components/camel-keycloak/src/main/java/org/apache/camel/component/keycloak/security/KeycloakSecurityHelper.java
+++ b/components/camel-keycloak/src/main/java/org/apache/camel/component/keycloak/security/KeycloakSecurityHelper.java
@@ -153,10 +153,12 @@ public final class KeycloakSecurityHelper {
 
         // Extract permissions from custom claims (primary approach for simple setups)
         Object permissionsClaim = token.getOtherClaims().get("permissions");
-        if (permissionsClaim instanceof java.util.Collection<?>) {
-            @SuppressWarnings("unchecked")
-            java.util.Collection<String> permissionsCollection = (java.util.Collection<String>) permissionsClaim;
-            permissions.addAll(permissionsCollection);
+        if (permissionsClaim instanceof java.util.Collection<?> permissionsCollection) {
+            for (Object perm : permissionsCollection) {
+                if (perm instanceof String s) {
+                    permissions.add(s);
+                }
+            }
         }
 
         // Also check for scope-based permissions
@@ -199,31 +201,29 @@ public final class KeycloakSecurityHelper {
 
         // Extract roles from realm_access claim
         Object realmAccess = introspectionResult.getClaim("realm_access");
-        if (realmAccess instanceof Map) {
-            @SuppressWarnings("unchecked")
-            Map<String, Object> realmAccessMap = (Map<String, Object>) realmAccess;
+        if (realmAccess instanceof Map<?, ?> realmAccessMap) {
             Object realmRoles = realmAccessMap.get("roles");
-            if (realmRoles instanceof Collection) {
-                @SuppressWarnings("unchecked")
-                Collection<String> realmRolesCollection = (Collection<String>) realmRoles;
-                roles.addAll(realmRolesCollection);
+            if (realmRoles instanceof Collection<?> realmRolesCollection) {
+                for (Object role : realmRolesCollection) {
+                    if (role instanceof String s) {
+                        roles.add(s);
+                    }
+                }
             }
         }
 
         // Extract client roles from resource_access claim
         Object resourceAccess = introspectionResult.getClaim("resource_access");
-        if (resourceAccess instanceof Map) {
-            @SuppressWarnings("unchecked")
-            Map<String, Object> resourceAccessMap = (Map<String, Object>) resourceAccess;
+        if (resourceAccess instanceof Map<?, ?> resourceAccessMap) {
             Object clientAccess = resourceAccessMap.get(clientId);
-            if (clientAccess instanceof Map) {
-                @SuppressWarnings("unchecked")
-                Map<String, Object> clientAccessMap = (Map<String, Object>) clientAccess;
+            if (clientAccess instanceof Map<?, ?> clientAccessMap) {
                 Object clientRoles = clientAccessMap.get("roles");
-                if (clientRoles instanceof Collection) {
-                    @SuppressWarnings("unchecked")
-                    Collection<String> clientRolesCollection = (Collection<String>) clientRoles;
-                    roles.addAll(clientRolesCollection);
+                if (clientRoles instanceof Collection<?> clientRolesCollection) {
+                    for (Object role : clientRolesCollection) {
+                        if (role instanceof String s) {
+                            roles.add(s);
+                        }
+                    }
                 }
             }
         }
@@ -243,10 +243,12 @@ public final class KeycloakSecurityHelper {
 
         // Extract permissions from custom claims
         Object permissionsClaim = introspectionResult.getClaim("permissions");
-        if (permissionsClaim instanceof Collection) {
-            @SuppressWarnings("unchecked")
-            Collection<String> permissionsCollection = (Collection<String>) permissionsClaim;
-            permissions.addAll(permissionsCollection);
+        if (permissionsClaim instanceof Collection<?> permissionsCollection) {
+            for (Object perm : permissionsCollection) {
+                if (perm instanceof String s) {
+                    permissions.add(s);
+                }
+            }
         }
 
         // Also check for scope-based permissions


(camel) 02/07: (chores): modernize instanceof checks in camel-management

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit fa47be2bdf2d810619625cf30562ae43930c7ed9
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Feb 10 08:31:09 2026 +0000

    (chores): modernize instanceof checks in camel-management
---
 .../DefaultManagementObjectStrategy.java           | 244 ++++++++++-----------
 1 file changed, 119 insertions(+), 125 deletions(-)

diff --git a/core/camel-management/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java b/core/camel-management/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
index a60aee95d261..6db5f7972358 100644
--- a/core/camel-management/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
+++ b/core/camel-management/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
@@ -332,9 +332,8 @@ public class DefaultManagementObjectStrategy implements ManagementObjectStrategy
 
         ProcessorDefinition<?> definition = (ProcessorDefinition<?>) node;
 
-        if (definition instanceof RecipientListDefinition) {
+        if (definition instanceof RecipientListDefinition && processor instanceof Pipeline pipeline) {
             // special for RecipientListDefinition, as the processor is wrapped in a pipeline as last
-            Pipeline pipeline = (Pipeline) processor;
             for (Processor value : pipeline.next()) {
                 processor = value;
             }
@@ -349,117 +348,112 @@ public class DefaultManagementObjectStrategy implements ManagementObjectStrategy
                 return false;
             }
 
-            if (target instanceof ConvertBodyProcessor) {
-                answer = new ManagedConvertBody(context, (ConvertBodyProcessor) target, definition);
-            } else if (target instanceof ConvertHeaderProcessor) {
-                answer = new ManagedConvertHeader(context, (ConvertHeaderProcessor) target, definition);
-            } else if (target instanceof ConvertVariableProcessor) {
-                answer = new ManagedConvertVariable(context, (ConvertVariableProcessor) target, definition);
-            } else if (target instanceof ChoiceProcessor) {
-                answer = new ManagedChoice(context, (ChoiceProcessor) target, definition);
-            } else if (target instanceof ClaimCheckProcessor) {
-                answer = new ManagedClaimCheck(context, (ClaimCheckProcessor) target, definition);
-            } else if (target instanceof Delayer) {
-                answer = new ManagedDelayer(context, (Delayer) target, definition);
-            } else if (target instanceof DisabledProcessor) {
-                answer = new ManagedDisabled(context, (DisabledProcessor) target, definition);
+            if (target instanceof ConvertBodyProcessor cbp) {
+                answer = new ManagedConvertBody(context, cbp, definition);
+            } else if (target instanceof ConvertHeaderProcessor chp) {
+                answer = new ManagedConvertHeader(context, chp, definition);
+            } else if (target instanceof ConvertVariableProcessor cvp) {
+                answer = new ManagedConvertVariable(context, cvp, definition);
+            } else if (target instanceof ChoiceProcessor cp) {
+                answer = new ManagedChoice(context, cp, definition);
+            } else if (target instanceof ClaimCheckProcessor ccp) {
+                answer = new ManagedClaimCheck(context, ccp, definition);
+            } else if (target instanceof Delayer d) {
+                answer = new ManagedDelayer(context, d, definition);
+            } else if (target instanceof DisabledProcessor dp) {
+                answer = new ManagedDisabled(context, dp, definition);
             } else if (target instanceof TryProcessor tryProc) {
                 answer = new ManagedDoTry(context, tryProc, cast(definition));
-            } else if (target instanceof CatchProcessor) {
-                answer = new ManagedDoCatch(context, (CatchProcessor) target, cast(definition));
-            } else if (target instanceof FinallyProcessor) {
-                answer = new ManagedDoFinally(context, (FinallyProcessor) target, cast(definition));
-            } else if (target instanceof Throttler) {
-                answer = new ManagedThrottler(context, (Throttler) target, definition);
-            } else if (target instanceof DynamicRouter) {
-                answer = new ManagedDynamicRouter(context, (DynamicRouter) target, cast(definition));
-            } else if (target instanceof RoutingSlip) {
-                answer = new ManagedRoutingSlip(context, (RoutingSlip) target, cast(definition));
-            } else if (target instanceof FilterProcessor) {
-                answer = new ManagedFilter(context, (FilterProcessor) target, (ExpressionNode) definition);
-            } else if (target instanceof LogProcessor) {
-                answer = new ManagedLog(context, (LogProcessor) target, definition);
-            } else if (target instanceof LoopProcessor) {
-                answer = new ManagedLoop(context, (LoopProcessor) target, cast(definition));
-            } else if (target instanceof MarshalProcessor) {
-                answer = new ManagedMarshal(context, (MarshalProcessor) target, cast(definition));
-            } else if (target instanceof UnmarshalProcessor) {
-                answer = new ManagedUnmarshal(context, (UnmarshalProcessor) target, cast(definition));
-            } else if (target instanceof FailOverLoadBalancer) {
-                answer = new ManagedFailoverLoadBalancer(
-                        context, (FailOverLoadBalancer) target, cast(definition));
-            } else if (target instanceof RandomLoadBalancer) {
-                answer = new ManagedRandomLoadBalancer(
-                        context, (RandomLoadBalancer) target, cast(definition));
-            } else if (target instanceof RoundRobinLoadBalancer) {
-                answer = new ManagedRoundRobinLoadBalancer(
-                        context, (RoundRobinLoadBalancer) target, cast(definition));
-            } else if (target instanceof StickyLoadBalancer) {
-                answer = new ManagedStickyLoadBalancer(
-                        context, (StickyLoadBalancer) target, cast(definition));
-            } else if (target instanceof TopicLoadBalancer) {
-                answer = new ManagedTopicLoadBalancer(context, (TopicLoadBalancer) target, cast(definition));
-            } else if (target instanceof WeightedLoadBalancer) {
-                answer = new ManagedWeightedLoadBalancer(
-                        context, (WeightedLoadBalancer) target, cast(definition));
-            } else if (target instanceof RecipientList) {
-                answer = new ManagedRecipientList(context, (RecipientList) target, cast(definition));
-            } else if (target instanceof Splitter) {
-                answer = new ManagedSplitter(context, (Splitter) target, cast(definition));
-            } else if (target instanceof MulticastProcessor) {
-                answer = new ManagedMulticast(context, (MulticastProcessor) target, definition);
-            } else if (target instanceof SamplingThrottler) {
-                answer = new ManagedSamplingThrottler(context, (SamplingThrottler) target, definition);
-            } else if (target instanceof Resequencer) {
-                answer = new ManagedResequencer(context, (Resequencer) target, definition);
-            } else if (target instanceof RollbackProcessor) {
-                answer = new ManagedRollback(context, (RollbackProcessor) target, definition);
-            } else if (target instanceof StreamResequencer) {
-                answer = new ManagedResequencer(context, (StreamResequencer) target, definition);
-            } else if (target instanceof SetBodyProcessor) {
-                answer = new ManagedSetBody(context, (SetBodyProcessor) target, cast(definition));
-            } else if (target instanceof RemoveHeaderProcessor) {
-                answer = new ManagedRemoveHeader(context, (RemoveHeaderProcessor) target, definition);
-            } else if (target instanceof RemoveHeadersProcessor) {
-                answer = new ManagedRemoveHeaders(context, (RemoveHeadersProcessor) target, definition);
-            } else if (target instanceof SetHeaderProcessor) {
-                answer = new ManagedSetHeader(context, (SetHeaderProcessor) target, cast(definition));
-            } else if (target instanceof SetHeadersProcessor) {
-                answer = new ManagedSetHeaders(context, (SetHeadersProcessor) target, cast(definition));
-            } else if (target instanceof SetVariableProcessor) {
-                answer = new ManagedSetVariable(context, (SetVariableProcessor) target, cast(definition));
-            } else if (target instanceof SetVariablesProcessor) {
-                answer = new ManagedSetVariables(context, (SetVariablesProcessor) target, cast(definition));
-            } else if (target instanceof RemovePropertyProcessor) {
-                answer = new ManagedRemoveProperty(context, (RemovePropertyProcessor) target, definition);
-            } else if (target instanceof RemovePropertiesProcessor) {
-                answer = new ManagedRemoveProperties(context, (RemovePropertiesProcessor) target, definition);
-            } else if (target instanceof RemoveVariableProcessor) {
-                answer = new ManagedRemoveVariable(context, (RemoveVariableProcessor) target, definition);
-            } else if (target instanceof SetPropertyProcessor) {
-                answer = new ManagedSetProperty(context, (SetPropertyProcessor) target, cast(definition));
-            } else if (target instanceof ExchangePatternProcessor) {
-                answer = new ManagedSetExchangePattern(context, (ExchangePatternProcessor) target, definition);
-            } else if (target instanceof ScriptProcessor) {
-                answer = new ManagedScript(context, (ScriptProcessor) target, cast(definition));
-            } else if (target instanceof StepProcessor) {
-                answer = new ManagedStep(context, (StepProcessor) target, definition);
-            } else if (target instanceof StopProcessor) {
-                answer = new ManagedStop(context, (StopProcessor) target, definition);
-            } else if (target instanceof ThreadsProcessor) {
-                answer = new ManagedThreads(context, (ThreadsProcessor) target, definition);
-            } else if (target instanceof ThrowExceptionProcessor) {
-                answer = new ManagedThrowException(context, (ThrowExceptionProcessor) target, definition);
+            } else if (target instanceof CatchProcessor catchProc) {
+                answer = new ManagedDoCatch(context, catchProc, cast(definition));
+            } else if (target instanceof FinallyProcessor fp) {
+                answer = new ManagedDoFinally(context, fp, cast(definition));
+            } else if (target instanceof Throttler t) {
+                answer = new ManagedThrottler(context, t, definition);
+            } else if (target instanceof DynamicRouter dr) {
+                answer = new ManagedDynamicRouter(context, dr, cast(definition));
+            } else if (target instanceof RoutingSlip rs) {
+                answer = new ManagedRoutingSlip(context, rs, cast(definition));
+            } else if (target instanceof FilterProcessor fp) {
+                answer = new ManagedFilter(context, fp, (ExpressionNode) definition);
+            } else if (target instanceof LogProcessor lp) {
+                answer = new ManagedLog(context, lp, definition);
+            } else if (target instanceof LoopProcessor loopProc) {
+                answer = new ManagedLoop(context, loopProc, cast(definition));
+            } else if (target instanceof MarshalProcessor mp) {
+                answer = new ManagedMarshal(context, mp, cast(definition));
+            } else if (target instanceof UnmarshalProcessor up) {
+                answer = new ManagedUnmarshal(context, up, cast(definition));
+            } else if (target instanceof FailOverLoadBalancer folb) {
+                answer = new ManagedFailoverLoadBalancer(context, folb, cast(definition));
+            } else if (target instanceof RandomLoadBalancer rlb) {
+                answer = new ManagedRandomLoadBalancer(context, rlb, cast(definition));
+            } else if (target instanceof RoundRobinLoadBalancer rrlb) {
+                answer = new ManagedRoundRobinLoadBalancer(context, rrlb, cast(definition));
+            } else if (target instanceof StickyLoadBalancer slb) {
+                answer = new ManagedStickyLoadBalancer(context, slb, cast(definition));
+            } else if (target instanceof TopicLoadBalancer tlb) {
+                answer = new ManagedTopicLoadBalancer(context, tlb, cast(definition));
+            } else if (target instanceof WeightedLoadBalancer wlb) {
+                answer = new ManagedWeightedLoadBalancer(context, wlb, cast(definition));
+            } else if (target instanceof RecipientList rl) {
+                answer = new ManagedRecipientList(context, rl, cast(definition));
+            } else if (target instanceof Splitter s) {
+                answer = new ManagedSplitter(context, s, cast(definition));
+            } else if (target instanceof MulticastProcessor mcp) {
+                answer = new ManagedMulticast(context, mcp, definition);
+            } else if (target instanceof SamplingThrottler st) {
+                answer = new ManagedSamplingThrottler(context, st, definition);
+            } else if (target instanceof Resequencer r) {
+                answer = new ManagedResequencer(context, r, definition);
+            } else if (target instanceof RollbackProcessor rp) {
+                answer = new ManagedRollback(context, rp, definition);
+            } else if (target instanceof StreamResequencer sr) {
+                answer = new ManagedResequencer(context, sr, definition);
+            } else if (target instanceof SetBodyProcessor sbp) {
+                answer = new ManagedSetBody(context, sbp, cast(definition));
+            } else if (target instanceof RemoveHeaderProcessor rhp) {
+                answer = new ManagedRemoveHeader(context, rhp, definition);
+            } else if (target instanceof RemoveHeadersProcessor rhsp) {
+                answer = new ManagedRemoveHeaders(context, rhsp, definition);
+            } else if (target instanceof SetHeaderProcessor shp) {
+                answer = new ManagedSetHeader(context, shp, cast(definition));
+            } else if (target instanceof SetHeadersProcessor shsp) {
+                answer = new ManagedSetHeaders(context, shsp, cast(definition));
+            } else if (target instanceof SetVariableProcessor svp) {
+                answer = new ManagedSetVariable(context, svp, cast(definition));
+            } else if (target instanceof SetVariablesProcessor svsp) {
+                answer = new ManagedSetVariables(context, svsp, cast(definition));
+            } else if (target instanceof RemovePropertyProcessor rpp) {
+                answer = new ManagedRemoveProperty(context, rpp, definition);
+            } else if (target instanceof RemovePropertiesProcessor rpsp) {
+                answer = new ManagedRemoveProperties(context, rpsp, definition);
+            } else if (target instanceof RemoveVariableProcessor rvp) {
+                answer = new ManagedRemoveVariable(context, rvp, definition);
+            } else if (target instanceof SetPropertyProcessor spp) {
+                answer = new ManagedSetProperty(context, spp, cast(definition));
+            } else if (target instanceof ExchangePatternProcessor epp) {
+                answer = new ManagedSetExchangePattern(context, epp, definition);
+            } else if (target instanceof ScriptProcessor scrp) {
+                answer = new ManagedScript(context, scrp, cast(definition));
+            } else if (target instanceof StepProcessor stepp) {
+                answer = new ManagedStep(context, stepp, definition);
+            } else if (target instanceof StopProcessor stopp) {
+                answer = new ManagedStop(context, stopp, definition);
+            } else if (target instanceof ThreadsProcessor tp) {
+                answer = new ManagedThreads(context, tp, definition);
+            } else if (target instanceof ThrowExceptionProcessor tep) {
+                answer = new ManagedThrowException(context, tep, definition);
             } else if (target instanceof TransformProcessor) {
                 answer = new ManagedTransformer(context, target, cast(definition));
             } else if (target instanceof DataTypeProcessor) {
                 answer = new ManagedDataTypeTransformer(context, target, cast(definition));
-            } else if (target instanceof PredicateValidatingProcessor) {
-                answer = new ManagedValidate(context, (PredicateValidatingProcessor) target, cast(definition));
-            } else if (target instanceof WireTapProcessor) {
-                answer = new ManagedWireTapProcessor(context, (WireTapProcessor) target, definition);
-            } else if (target instanceof SendDynamicProcessor) {
-                answer = new ManagedSendDynamicProcessor(context, (SendDynamicProcessor) target, definition);
+            } else if (target instanceof PredicateValidatingProcessor pvp) {
+                answer = new ManagedValidate(context, pvp, cast(definition));
+            } else if (target instanceof WireTapProcessor wtp) {
+                answer = new ManagedWireTapProcessor(context, wtp, definition);
+            } else if (target instanceof SendDynamicProcessor sdp) {
+                answer = new ManagedSendDynamicProcessor(context, sdp, definition);
             } else if (target instanceof SendProcessor sp) {
                 // special for sending to throughput logger
                 if (sp.getDestination() instanceof LogEndpoint le && le.getLogger() instanceof ThroughputLogger tl) {
@@ -467,27 +461,27 @@ public class DefaultManagementObjectStrategy implements ManagementObjectStrategy
                 }
                 // regular send processor
                 if (answer == null) {
-                    answer = new ManagedSendProcessor(context, (SendProcessor) target, definition);
+                    answer = new ManagedSendProcessor(context, sp, definition);
                 }
-            } else if (target instanceof BeanProcessor) {
-                answer = new ManagedBeanProcessor(context, (BeanProcessor) target, definition);
-            } else if (target instanceof IdempotentConsumer) {
-                answer = new ManagedIdempotentConsumer(
-                        context, (IdempotentConsumer) target, cast(definition));
-            } else if (target instanceof AggregateProcessor) {
-                answer = new ManagedAggregateProcessor(context, (AggregateProcessor) target, cast(definition));
-            } else if (target instanceof Enricher) {
-                answer = new ManagedEnricher(context, (Enricher) target, cast(definition));
+            } else if (target instanceof BeanProcessor bp) {
+                answer = new ManagedBeanProcessor(context, bp, definition);
+            } else if (target instanceof IdempotentConsumer ic) {
+                answer = new ManagedIdempotentConsumer(context, ic, cast(definition));
+            } else if (target instanceof AggregateProcessor ap) {
+                answer = new ManagedAggregateProcessor(context, ap, cast(definition));
+            } else if (target instanceof Enricher e) {
+                answer = new ManagedEnricher(context, e, cast(definition));
             } else if (target instanceof PollProcessor pp) {
                 answer = new ManagedPoll(context, pp, cast(definition));
-            } else if (target instanceof PollEnricher) {
-                answer = new ManagedPollEnricher(context, (PollEnricher) target, cast(definition));
+            } else if (target instanceof PollEnricher pe) {
+                answer = new ManagedPollEnricher(context, pe, cast(definition));
             }
 
             // special for custom load balancer
             if (definition instanceof LoadBalanceDefinition lb) {
-                if (lb.getLoadBalancerType() instanceof CustomLoadBalancerDefinition) {
-                    answer = new ManagedCustomLoadBalancer(context, (LoadBalancer) target, (LoadBalanceDefinition) definition);
+                if (lb.getLoadBalancerType() instanceof CustomLoadBalancerDefinition
+                        && target instanceof LoadBalancer loadBalancer) {
+                    answer = new ManagedCustomLoadBalancer(context, loadBalancer, lb);
                 }
             }
 
@@ -497,16 +491,16 @@ public class DefaultManagementObjectStrategy implements ManagementObjectStrategy
             }
 
             // no answer yet, so unwrap any delegates and try again
-            if (target instanceof DelegateProcessor) {
-                target = ((DelegateProcessor) target).getProcessor();
+            if (target instanceof DelegateProcessor delegateProcessor) {
+                target = delegateProcessor.getProcessor();
             } else {
                 // no delegate so we dont have any target to try next
                 break;
             }
         }
 
-        if (answer == null && definition instanceof ProcessDefinition) {
-            answer = new ManagedProcess(context, target, (ProcessDefinition) definition);
+        if (answer == null && definition instanceof ProcessDefinition pd) {
+            answer = new ManagedProcess(context, target, pd);
         } else if (answer == null) {
             // fallback to a generic processor
             answer = new ManagedProcessor(context, target, definition);


(camel) 06/07: (chores): modernize instanceof checks in camel-datasonnet

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit bbdc5df2d2860fda4fee8cb874b8dbbab341de76
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Feb 10 08:41:10 2026 +0000

    (chores): modernize instanceof checks in camel-datasonnet
---
 .../main/java/org/apache/camel/language/datasonnet/CML.java  | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/components/camel-datasonnet/src/main/java/org/apache/camel/language/datasonnet/CML.java b/components/camel-datasonnet/src/main/java/org/apache/camel/language/datasonnet/CML.java
index dee5aaf637d0..6c1db12711d9 100644
--- a/components/camel-datasonnet/src/main/java/org/apache/camel/language/datasonnet/CML.java
+++ b/components/camel-datasonnet/src/main/java/org/apache/camel/language/datasonnet/CML.java
@@ -88,8 +88,8 @@ public final class CML extends Library {
     }
 
     private Val header(Val key, DataFormatService dataformats) {
-        if (key instanceof Val.Str) {
-            return valFrom(exchange.get().getMessage().getHeader(((Val.Str) key).value()), dataformats);
+        if (key instanceof Val.Str str) {
+            return valFrom(exchange.get().getMessage().getHeader(str.value()), dataformats);
         }
         throw new IllegalArgumentException("Expected String got: " + key.prettyName());
     }
@@ -102,16 +102,16 @@ public final class CML extends Library {
     }
 
     private Val exchangeProperty(Val key, DataFormatService dataformats) {
-        if (key instanceof Val.Str) {
-            return valFrom(exchange.get().getProperty(((Val.Str) key).value()), dataformats);
+        if (key instanceof Val.Str str) {
+            return valFrom(exchange.get().getProperty(str.value()), dataformats);
         }
         throw new IllegalArgumentException("Expected String got: " + key.prettyName());
     }
 
     private Val valFrom(Object obj, DataFormatService dataformats) {
         Document doc;
-        if (obj instanceof Document) {
-            doc = (Document) obj;
+        if (obj instanceof Document document) {
+            doc = document;
         } else {
             doc = new DefaultDocument(obj, MediaTypes.APPLICATION_JAVA);
         }