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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git


The following commit(s) were added to refs/heads/main by this push:
     new de5c0337cb5 fix: NPE when a Spring Boot config source resolves to an 
empty YAML object (#1859)
de5c0337cb5 is described below

commit de5c0337cb5f8768ddff36806537c081e5e4bd79
Author: Nagy Vilmos <[email protected]>
AuthorDate: Mon Jul 20 20:01:41 2026 +0200

    fix: NPE when a Spring Boot config source resolves to an empty YAML object 
(#1859)
    
    Previously, Camel could start successfully when a loaded YAML file's root
    object was empty (`{}`). With Spring Boot's recent changes
    (https://github.com/spring-projects/spring-boot/issues/48958), when the root
    object is empty (`{}`), the resulting `EnumerablePropertySource` now 
contains
    a `null -> ""` mapping (previously this property source was empty). Because
    of this, every call to `eps.getPropertyNames()` must now guard against a
    null name.
    
    Confirmed this is a regression: without this fix, the new test throws an NPE
    against the current Spring Boot version. The same test passes against Camel
    4.20 (pre-upgrade), which used an older Spring Boot version where this
    property source was empty rather than containing a null key.
---
 .../camel/spring/boot/CamelAutoConfiguration.java  |  4 +-
 .../CamelSecurityPolicyAutoConfiguration.java      |  2 +-
 ...nfigurationWithAdditionalConfigurationTest.java | 61 ++++++++++++++++++++++
 .../additional-config/empty-additional-config.yaml |  1 +
 4 files changed, 65 insertions(+), 3 deletions(-)

diff --git 
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
 
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index 28f902447e5..a3429047a20 100644
--- 
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++ 
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -248,7 +248,7 @@ public class CamelAutoConfiguration {
             cev.getPropertySources().forEach(ps -> {
                 if (ps instanceof EnumerablePropertySource<?> eps) {
                     for (String n : eps.getPropertyNames()) {
-                        if (n.startsWith("camel.main.")) {
+                        if (n != null && n.startsWith("camel.main.")) {
                             answer.put(n, cev.getProperty(n, ""));
                         }
                     }
@@ -265,7 +265,7 @@ public class CamelAutoConfiguration {
         env.getPropertySources().forEach(ps -> {
             if (ps instanceof EnumerablePropertySource eps) {
                 for (String n : eps.getPropertyNames()) {
-                    if (n.startsWith("camel.variable.")) {
+                    if (n != null && n.startsWith("camel.variable.")) {
                         String v = env.getRequiredProperty(n);
                         n = n.substring(15);
                         answer.put(n, v);
diff --git 
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/security/CamelSecurityPolicyAutoConfiguration.java
 
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/security/CamelSecurityPolicyAutoConfiguration.java
index 5fc7414c187..93d2dcbd6dc 100644
--- 
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/security/CamelSecurityPolicyAutoConfiguration.java
+++ 
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/security/CamelSecurityPolicyAutoConfiguration.java
@@ -111,7 +111,7 @@ public class CamelSecurityPolicyAutoConfiguration {
             ce.getPropertySources().forEach(ps -> {
                 if (ps instanceof EnumerablePropertySource<?> eps) {
                     for (String name : eps.getPropertyNames()) {
-                        if (name.startsWith("camel.") && 
!name.startsWith("camel.security.")) {
+                        if (name != null && name.startsWith("camel.") && 
!name.startsWith("camel.security.")) {
                             Object value = environment.getProperty(name);
                             if (value != null) {
                                 properties.putIfAbsent(name, value);
diff --git 
a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationWithAdditionalConfigurationTest.java
 
b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationWithAdditionalConfigurationTest.java
new file mode 100644
index 00000000000..8f51fd5481a
--- /dev/null
+++ 
b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationWithAdditionalConfigurationTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spring.boot;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.Mockito.mock;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.test.spring.junit6.CamelSpringBootTest;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+
+public class CamelAutoConfigurationWithAdditionalConfigurationTest {
+
+    @DirtiesContext
+    @CamelSpringBootTest
+    @EnableAutoConfiguration
+    @SpringBootTest(properties = { 
"spring.config.additional-location=classpath:/additional-config/empty-additional-config.yaml"
 })
+    public static class WhenEmptyFileIsOnAdditionalConfigTest {
+
+        // Collaborators fixtures
+
+        @Autowired
+        CamelContext camelContext;
+
+        // Tests
+
+        @Test
+        public void createCamelContext() {
+            assertNotNull(camelContext);
+        }
+
+        @Configuration
+        public static class TestConfig {
+            @Bean
+            CamelContextConfiguration camelContextConfiguration() {
+                return mock(CamelContextConfiguration.class);
+            }
+        }
+
+    }
+}
diff --git 
a/core/camel-spring-boot/src/test/resources/additional-config/empty-additional-config.yaml
 
b/core/camel-spring-boot/src/test/resources/additional-config/empty-additional-config.yaml
new file mode 100644
index 00000000000..9e26dfeeb6e
--- /dev/null
+++ 
b/core/camel-spring-boot/src/test/resources/additional-config/empty-additional-config.yaml
@@ -0,0 +1 @@
+{}
\ No newline at end of file

Reply via email to