From 1228d432e68a1a83e54a2a6fba4ac9ff997415ba Mon Sep 17 00:00:00 2001 From: Otavio Rodolfo Piske Date: Thu, 28 Sep 2023 08:46:27 +0200 Subject: [PATCH] (chores) camel-core: vet and/or improve methods with varargs This should vet, protect/reduce the potential for heap pollution problems --- .../apache/camel/builder/RouteBuilder.java | 3 +- .../apache/camel/model/CatchDefinition.java | 38 ++++++++++++++++++- .../camel/model/ProcessorDefinition.java | 35 ++++++++++++++++- .../model/RouteConfigurationDefinition.java | 3 +- .../component/AbstractApiComponent.java | 31 ++++++++------- 5 files changed, 93 insertions(+), 17 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 048ccc054166e..0c72cba8f955c 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 OnExceptionDefinition onException(Class exception) { * @param exceptions list of exceptions to catch * @return the builder */ - public OnExceptionDefinition onException(Class... exceptions) { + @SafeVarargs + public final OnExceptionDefinition onException(Class... exceptions) { OnExceptionDefinition last = null; for (Class 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 7ebba65904a5b..5b7c03da9c2c5 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 void setExceptionClasses(List> exceptionClasse // Fluent API // ------------------------------------------------------------------------- + /** + * The exception(s) to catch. + * + * @param exception one or more exceptions + * @return the builder + */ + public CatchDefinition exception(Class 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 exception1, Class 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 exception1, Class exception2, + Class 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... exceptions) { + @SafeVarargs + public final CatchDefinition exception(Class... 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 e12a6b83c4951..92c07158e477e 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 OnExceptionDefinition onException(Class exceptionTyp return answer; } + /** + * Exception clause 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 exceptionType1, Class exceptionType2) { + OnExceptionDefinition answer = new OnExceptionDefinition(Arrays.asList(exceptionType1, exceptionType2)); + addOutput(answer); + return answer; + } + + /** + * Exception clause 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 exceptionType1, Class exceptionType2, + Class exceptionType3) { + OnExceptionDefinition answer = new OnExceptionDefinition(Arrays.asList(exceptionType1, exceptionType2, exceptionType3)); + addOutput(answer); + return answer; + } + /** * Exception clause for catching certain exceptions and * handling them. @@ -2095,7 +2127,8 @@ public OnExceptionDefinition onException(Class exceptionTyp * @param exceptions list of exceptions to catch * @return the exception builder to configure */ - public OnExceptionDefinition onException(Class... exceptions) { + @SafeVarargs + public final OnExceptionDefinition onException(Class... 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 b7e9d900e8e5e..da3a3347996ae 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 OnExceptionDefinition onException(Class exceptionTyp * @param exceptions list of exceptions to catch * @return the exception builder to configure */ - public OnExceptionDefinition onException(Class... exceptions) { + @SafeVarargs + public final OnExceptionDefinition onException(Class... exceptions) { OnExceptionDefinition answer = new OnExceptionDefinition(Arrays.asList(exceptions)); answer.setRouteConfiguration(this); onExceptions.add(answer); diff --git a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java index f3305844793c8..5dbc1721f1f9a 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java @@ -48,10 +48,10 @@ public abstract class AbstractApiComponent & ApiName, T, S ext /** * Deprecated constructor for AbstractApiComponent. * - * @deprecated Use {@link AbstractApiComponent#AbstractApiComponent(Class, ApiCollection)} - * @param endpointClass This is deprecated. Do not use - * @param apiNameClass The API name class - * @param collection The collection of API methods + * @deprecated Use {@link AbstractApiComponent#AbstractApiComponent(Class, ApiCollection)} + * @param endpointClass This is deprecated. Do not use + * @param apiNameClass The API name class + * @param collection The collection of API methods */ @Deprecated public AbstractApiComponent(Class endpointClass, Class apiNameClass, S collection) { @@ -61,21 +61,25 @@ public AbstractApiComponent(Class endpointClass, Class ap /** * Deprecated constructor for AbstractApiComponent. * - * @deprecated Use {@link AbstractApiComponent#AbstractApiComponent(CamelContext, Class, ApiCollection)} instead - * @param context The CamelContext - * @param endpointClass This is deprecated. Do not use - * @param apiNameClass The API name class - * @param collection The collection of API methods + * @deprecated Use + * {@link AbstractApiComponent#AbstractApiComponent(CamelContext, Class, ApiCollection)} + * instead + * @param context The CamelContext + * @param endpointClass This is deprecated. Do not use + * @param apiNameClass The API name class + * @param collection The collection of API methods */ @Deprecated - public AbstractApiComponent(CamelContext context, Class endpointClass, Class apiNameClass, S collection) { + public AbstractApiComponent(CamelContext context, Class endpointClass, Class apiNameClass, + S collection) { this(context, apiNameClass, collection); } /** * Creates a new AbstractApiComponent + * * @param apiNameClass The API name class - * @param collection The collection of API methods + * @param collection The collection of API methods */ protected AbstractApiComponent(Class apiNameClass, S collection) { this.collection = collection; @@ -84,9 +88,10 @@ protected AbstractApiComponent(Class apiNameClass, S collection) { /** * Creates a new AbstractApiComponent - * @param context The CamelContext + * + * @param context The CamelContext * @param apiNameClass The API name class - * @param collection The collection of API methods + * @param collection The collection of API methods */ protected AbstractApiComponent(CamelContext context, Class apiNameClass, S collection) { super(context);