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 2023/09/29 09:12:18 UTC

[camel] branch main updated: (chores) camel-core: vet and/or improve methods with varargs

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


The following commit(s) were added to refs/heads/main by this push:
     new 74fc44449bf (chores) camel-core: vet and/or improve methods with varargs
74fc44449bf is described below

commit 74fc44449bf402fc8fd2387dbae3a9d2791fe777
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Thu Sep 28 08:46:27 2023 +0200

    (chores) camel-core: vet and/or improve methods with varargs
    
    This should vet, protect/reduce the potential for heap pollution problems
---
 .../org/apache/camel/builder/RouteBuilder.java     |  3 +-
 .../org/apache/camel/model/CatchDefinition.java    | 38 +++++++++++++++++++++-
 .../apache/camel/model/ProcessorDefinition.java    | 35 +++++++++++++++++++-
 .../camel/model/RouteConfigurationDefinition.java  |  3 +-
 4 files changed, 75 insertions(+), 4 deletions(-)

diff --git a/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java b/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java
index 048ccc05416..0c72cba8f95 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -573,7 +573,8 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
      * @param  exceptions list of exceptions to catch
      * @return            the builder
      */
-    public OnExceptionDefinition onException(Class<? extends Throwable>... exceptions) {
+    @SafeVarargs
+    public final OnExceptionDefinition onException(Class<? extends Throwable>... exceptions) {
         OnExceptionDefinition last = null;
         for (Class<? extends Throwable> ex : exceptions) {
             last = last == null ? onException(ex) : last.onException(ex);
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/CatchDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/CatchDefinition.java
index 7ebba65904a..5b7c03da9c2 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/CatchDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/CatchDefinition.java
@@ -95,13 +95,49 @@ public class CatchDefinition extends OutputDefinition<CatchDefinition> {
     // Fluent API
     // -------------------------------------------------------------------------
 
+    /**
+     * The exception(s) to catch.
+     *
+     * @param  exception one or more exceptions
+     * @return           the builder
+     */
+    public CatchDefinition exception(Class<? extends Throwable> exception) {
+        return exception(List.of(exception));
+    }
+
+    /**
+     * The exception(s) to catch.
+     *
+     * @param  exception1 fist exception
+     * @param  exception2 second exception
+     * @return            the builder
+     */
+    public CatchDefinition exception(Class<? extends Throwable> exception1, Class<? extends Throwable> exception2) {
+        return exception(List.of(exception1, exception2));
+    }
+
+    /**
+     * The exception(s) to catch.
+     *
+     * @param  exception1 fist exception
+     * @param  exception2 second exception
+     * @param  exception3 third exception
+     * @return            the builder
+     */
+    public CatchDefinition exception(
+            Class<? extends Throwable> exception1, Class<? extends Throwable> exception2,
+            Class<? extends Throwable> exception3) {
+        return exception(List.of(exception1, exception2, exception3));
+    }
+
     /**
      * The exception(s) to catch.
      *
      * @param  exceptions one or more exceptions
      * @return            the builder
      */
-    public CatchDefinition exception(Class<? extends Throwable>... exceptions) {
+    @SafeVarargs
+    public final CatchDefinition exception(Class<? extends Throwable>... exceptions) {
         return exception(List.of(exceptions));
     }
 
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index e12a6b83c49..92c07158e47 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -2088,6 +2088,38 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
         return answer;
     }
 
+    /**
+     * <a href="http://camel.apache.org/exception-clause.html">Exception clause</a> for catching certain exceptions and
+     * handling them.
+     *
+     * @param  exceptionType1 the first exception to catch
+     * @param  exceptionType2 the second exception to catch
+     * @return                the exception builder to configure
+     */
+    public OnExceptionDefinition onException(
+            Class<? extends Throwable> exceptionType1, Class<? extends Throwable> exceptionType2) {
+        OnExceptionDefinition answer = new OnExceptionDefinition(Arrays.asList(exceptionType1, exceptionType2));
+        addOutput(answer);
+        return answer;
+    }
+
+    /**
+     * <a href="http://camel.apache.org/exception-clause.html">Exception clause</a> for catching certain exceptions and
+     * handling them.
+     *
+     * @param  exceptionType1 the first exception to catch
+     * @param  exceptionType2 the second exception to catch
+     * @param  exceptionType3 the third exception to catch
+     * @return                the exception builder to configure
+     */
+    public OnExceptionDefinition onException(
+            Class<? extends Throwable> exceptionType1, Class<? extends Throwable> exceptionType2,
+            Class<? extends Throwable> exceptionType3) {
+        OnExceptionDefinition answer = new OnExceptionDefinition(Arrays.asList(exceptionType1, exceptionType2, exceptionType3));
+        addOutput(answer);
+        return answer;
+    }
+
     /**
      * <a href="http://camel.apache.org/exception-clause.html">Exception clause</a> for catching certain exceptions and
      * handling them.
@@ -2095,7 +2127,8 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
      * @param  exceptions list of exceptions to catch
      * @return            the exception builder to configure
      */
-    public OnExceptionDefinition onException(Class<? extends Throwable>... exceptions) {
+    @SafeVarargs
+    public final OnExceptionDefinition onException(Class<? extends Throwable>... exceptions) {
         OnExceptionDefinition answer = new OnExceptionDefinition(Arrays.asList(exceptions));
         addOutput(answer);
         return answer;
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteConfigurationDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteConfigurationDefinition.java
index b7e9d900e8e..da3a3347996 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteConfigurationDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteConfigurationDefinition.java
@@ -216,7 +216,8 @@ public class RouteConfigurationDefinition extends OptionalIdentifiedDefinition<R
      * @param  exceptions list of exceptions to catch
      * @return            the exception builder to configure
      */
-    public OnExceptionDefinition onException(Class<? extends Throwable>... exceptions) {
+    @SafeVarargs
+    public final OnExceptionDefinition onException(Class<? extends Throwable>... exceptions) {
         OnExceptionDefinition answer = new OnExceptionDefinition(Arrays.asList(exceptions));
         answer.setRouteConfiguration(this);
         onExceptions.add(answer);