You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2026/04/29 08:44:30 UTC

(camel-spring-boot) branch main updated: CAMEL-23378: avoid String to InputStream conversion (#1771)

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 52b017db006 CAMEL-23378: avoid String to InputStream conversion (#1771)
52b017db006 is described below

commit 52b017db006ca91947105986c08b8d1aa47e59ee
Author: Marco Carletti <mc...@ibm.com>
AuthorDate: Wed Apr 29 10:44:25 2026 +0200

    CAMEL-23378: avoid String to InputStream conversion (#1771)
---
 .../org/apache/camel/spring/boot/SpringTypeConverter.java |  8 ++++++++
 .../apache/camel/spring/boot/SpringTypeConverterTest.java | 15 +++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java
index e6e9c65282a..7578cf2db61 100644
--- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java
+++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.spring.boot;
 
+import java.io.InputStream;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -52,6 +53,13 @@ public class SpringTypeConverter extends TypeConverterSupport {
             return null;
         }
 
+        // do not attempt to convert String -> InputStream (or subclasses like FileInputStream).
+        // Spring's ObjectToObjectConverter finds FileInputStream(String) constructor and treats
+        // the String value as a file path instead of data content.
+        if (value instanceof String && InputStream.class.isAssignableFrom(type)) {
+            return null;
+        }
+
         TypeDescriptor sourceType = types.computeIfAbsent(value.getClass(), TypeDescriptor::valueOf);
         TypeDescriptor targetType = types.computeIfAbsent(type, TypeDescriptor::valueOf);
 
diff --git a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringTypeConverterTest.java b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringTypeConverterTest.java
index 44ce65011b2..5fd9e3d70f7 100644
--- a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringTypeConverterTest.java
+++ b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringTypeConverterTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.spring.boot;
 
+import java.io.FileInputStream;
+import java.io.InputStream;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
@@ -70,6 +72,19 @@ public class SpringTypeConverterTest {
         Assertions.assertNull(converter.convertTo(String.class, source));
     }
 
+    @Test
+    public void testStringToFileInputStreamConversionIsBlocked() {
+        // Spring's ObjectToObjectConverter sees FileInputStream(String) constructor and
+        // treats String content as a file path — must return null so Camel's own converters
+        // handle String -> InputStream correctly
+        Assertions.assertNull(converter.convertTo(FileInputStream.class, null, "some file content"));
+    }
+
+    @Test
+    public void testStringToInputStreamConversionIsBlocked() {
+        Assertions.assertNull(converter.convertTo(InputStream.class, null, "some file content"));
+    }
+
     public static class Person {
         private String name;
         private int age;