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/01/26 13:01:41 UTC
(camel) 03/41: (chores): modernize instanceof checks in camel-bean
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 25ba10adf4df8bb07e670e1115f24a28b22512c4
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Jan 26 10:31:08 2026 +0000
(chores): modernize instanceof checks in camel-bean
---
.../bean/AbstractCamelInvocationHandler.java | 8 ++++----
.../org/apache/camel/component/bean/MethodInfo.java | 20 ++++++++++----------
.../org/apache/camel/language/bean/BeanLanguage.java | 4 ++--
3 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/AbstractCamelInvocationHandler.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/AbstractCamelInvocationHandler.java
index 53f18b4855f9..5bc018b4ab01 100644
--- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/AbstractCamelInvocationHandler.java
+++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/AbstractCamelInvocationHandler.java
@@ -239,8 +239,8 @@ public abstract class AbstractCamelInvocationHandler implements InvocationHandle
if (cause != null) {
Throwable found = findSuitableException(cause, method);
if (found != null) {
- if (found instanceof Exception) {
- throw (Exception) found;
+ if (found instanceof Exception exception) {
+ throw exception;
} else {
// wrap as exception
throw new CamelExchangeException("Error processing exchange", exchange, cause);
@@ -250,8 +250,8 @@ public abstract class AbstractCamelInvocationHandler implements InvocationHandle
if (cause instanceof RuntimeCamelException) {
// if the inner cause is a runtime exception we can throw it
// directly
- if (cause.getCause() instanceof RuntimeException) {
- throw (RuntimeException) cause.getCause();
+ if (cause.getCause() instanceof RuntimeException runtimeexception) {
+ throw runtimeexception;
}
throw cause;
}
diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
index c69ccd4db163..6254cfecf208 100644
--- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
+++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
@@ -251,8 +251,8 @@ public class MethodInfo {
*/
public void setErrorHandler(Processor errorHandler) {
// special for @RecipientList which needs to be injected with error handler it should use
- if (recipientList instanceof ErrorHandlerAware) {
- ((ErrorHandlerAware) recipientList).setErrorHandler(errorHandler);
+ if (recipientList instanceof ErrorHandlerAware errorhandleraware) {
+ errorhandleraware.setErrorHandler(errorHandler);
}
}
@@ -309,9 +309,9 @@ public class MethodInfo {
Object result = invoke(method, pojo, arguments, exchange);
// the method may be a closure or chained method returning a callable which should be called
- if (result instanceof Callable) {
+ if (result instanceof Callable callable) {
LOG.trace("Method returned Callback which will be called: {}", result);
- Object callableResult = ((Callable) result).call();
+ Object callableResult = (callable).call();
if (callableResult != null) {
result = callableResult;
} else {
@@ -611,9 +611,9 @@ public class MethodInfo {
private Object[] evaluateParameterExpressions(Exchange exchange, Object body, Iterator<?> it) {
Object[] answer = new Object[expressions != null ? expressions.length : 1];
for (int i = 0; expressions == null || i < expressions.length; i++) {
- if (body instanceof StreamCache) {
+ if (body instanceof StreamCache streamcache2) {
// need to reset stream cache for each expression as you may access the message body in multiple parameters
- ((StreamCache) body).reset();
+ (streamcache2).reset();
}
// whether its vararg
@@ -654,9 +654,9 @@ public class MethodInfo {
*/
private Object evaluateVarargsParameterExpressions(Exchange exchange, Object body, Iterator<?> it) {
// special for varargs
- if (body instanceof StreamCache) {
+ if (body instanceof StreamCache streamcache) {
// need to reset stream cache for each expression as you may access the message body in multiple parameters
- ((StreamCache) body).reset();
+ (streamcache).reset();
}
List<Object> answer = new ArrayList<>();
int i = 0;
@@ -758,8 +758,8 @@ public class MethodInfo {
if (valid) {
// we need to unquote String parameters, as the enclosing quotes is there to denote a parameter value
- if (parameterValue instanceof String) {
- parameterValue = StringHelper.removeLeadingAndEndingQuotes((String) parameterValue);
+ if (parameterValue instanceof String string) {
+ parameterValue = StringHelper.removeLeadingAndEndingQuotes(string);
}
if (varargs) {
// use the value as-is
diff --git a/components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanLanguage.java b/components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanLanguage.java
index 2939f1e8b132..b87aa0b53025 100644
--- a/components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanLanguage.java
+++ b/components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanLanguage.java
@@ -134,8 +134,8 @@ public class BeanLanguage extends TypedLanguageSupport implements ScriptingLangu
throw new IllegalArgumentException("Bean language requires bean, beanType, or ref argument");
}
Object scope = property(Object.class, properties, 5, null);
- if (scope instanceof BeanScope) {
- answer.setScope((BeanScope) scope);
+ if (scope instanceof BeanScope beanscope) {
+ answer.setScope(beanscope);
} else if (scope != null) {
answer.setScope(BeanScope.valueOf(scope.toString()));
}