You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2024/05/15 05:39:17 UTC

(camel) 11/14: Fix possible NPE in cloud configuration

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

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

commit f7f39f0be56468844f1a7557456864f2468fea9b
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue May 14 14:44:05 2024 +0200

    Fix possible NPE in cloud configuration
---
 .../cloud/ServiceCallExpressionConfiguration.java   | 21 +++++++++------------
 ...ServiceCallServiceLoadBalancerConfiguration.java | 18 ++++++++----------
 2 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/cloud/ServiceCallExpressionConfiguration.java b/core/camel-core-model/src/main/java/org/apache/camel/model/cloud/ServiceCallExpressionConfiguration.java
index 188940f5a5b..873e3b45082 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/cloud/ServiceCallExpressionConfiguration.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/cloud/ServiceCallExpressionConfiguration.java
@@ -170,8 +170,7 @@ public class ServiceCallExpressionConfiguration extends ServiceCallConfiguration
                     = CamelContextHelper.lookup(camelContext, factoryKey, ServiceExpressionFactory.class);
             if (factory != null) {
                 // If a factory is found in the registry do not re-configure it
-                // as
-                // it should be pre-configured.
+                // as it should be pre-configured.
                 answer = factory.newInstance(camelContext);
             } else {
 
@@ -179,20 +178,18 @@ public class ServiceCallExpressionConfiguration extends ServiceCallConfiguration
                 try {
                     // Then use Service factory.
                     type = camelContext.getCamelContextExtension()
-                            .getFactoryFinder(ServiceCallDefinitionConstants.RESOURCE_PATH).findClass(factoryKey).orElse(null);
+                            .getFactoryFinder(ServiceCallDefinitionConstants.RESOURCE_PATH).findClass(factoryKey).orElseThrow();
                 } catch (Exception e) {
                     throw new NoFactoryAvailableException(ServiceCallDefinitionConstants.RESOURCE_PATH + factoryKey, e);
                 }
 
-                if (type != null) {
-                    if (ServiceExpressionFactory.class.isAssignableFrom(type)) {
-                        factory = (ServiceExpressionFactory) camelContext.getInjector().newInstance(type, false);
-                    } else {
-                        throw new IllegalArgumentException(
-                                "Resolving Expression: " + factoryKey
-                                                           + " detected type conflict: Not a ExpressionFactory implementation. Found: "
-                                                           + type.getName());
-                    }
+                if (ServiceExpressionFactory.class.isAssignableFrom(type)) {
+                    factory = (ServiceExpressionFactory) camelContext.getInjector().newInstance(type, false);
+                } else {
+                    throw new IllegalArgumentException(
+                            "Resolving Expression: " + factoryKey
+                                                       + " detected type conflict: Not a ExpressionFactory implementation. Found: "
+                                                       + type.getName());
                 }
 
                 try {
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceLoadBalancerConfiguration.java b/core/camel-core-model/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceLoadBalancerConfiguration.java
index fc310f0da00..ac703982093 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceLoadBalancerConfiguration.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/cloud/ServiceCallServiceLoadBalancerConfiguration.java
@@ -100,20 +100,18 @@ public class ServiceCallServiceLoadBalancerConfiguration extends ServiceCallConf
             try {
                 // Then use Service factory.
                 type = camelContext.getCamelContextExtension()
-                        .getFactoryFinder(ServiceCallDefinitionConstants.RESOURCE_PATH).findClass(factoryKey).orElse(null);
+                        .getFactoryFinder(ServiceCallDefinitionConstants.RESOURCE_PATH).findClass(factoryKey).orElseThrow();
             } catch (Exception e) {
                 throw new NoFactoryAvailableException(ServiceCallDefinitionConstants.RESOURCE_PATH + factoryKey, e);
             }
 
-            if (type != null) {
-                if (ServiceLoadBalancerFactory.class.isAssignableFrom(type)) {
-                    factory = (ServiceLoadBalancerFactory) camelContext.getInjector().newInstance(type, false);
-                } else {
-                    throw new IllegalArgumentException(
-                            "Resolving LoadBalancer: " + factoryKey
-                                                       + " detected type conflict: Not a LoadBalancerFactory implementation. Found: "
-                                                       + type.getName());
-                }
+            if (ServiceLoadBalancerFactory.class.isAssignableFrom(type)) {
+                factory = (ServiceLoadBalancerFactory) camelContext.getInjector().newInstance(type, false);
+            } else {
+                throw new IllegalArgumentException(
+                        "Resolving LoadBalancer: " + factoryKey
+                                                   + " detected type conflict: Not a LoadBalancerFactory implementation. Found: "
+                                                   + type.getName());
             }
 
             try {