Skip to content

Commit 0cfff5d

Browse files
committed
CAMEL-23378: avoid String to InputStream conversion
1 parent ac3a67d commit 0cfff5d

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.camel.spring.boot;
1818

19+
import java.io.InputStream;
1920
import java.util.Collection;
2021
import java.util.List;
2122
import java.util.Map;
@@ -52,6 +53,13 @@ public <T> T convertTo(Class<T> type, Exchange exchange, Object value) throws Ty
5253
return null;
5354
}
5455

56+
// do not attempt to convert String -> InputStream (or subclasses like FileInputStream).
57+
// Spring's ObjectToObjectConverter finds FileInputStream(String) constructor and treats
58+
// the String value as a file path instead of data content.
59+
if (value instanceof String && InputStream.class.isAssignableFrom(type)) {
60+
return null;
61+
}
62+
5563
TypeDescriptor sourceType = types.computeIfAbsent(value.getClass(), TypeDescriptor::valueOf);
5664
TypeDescriptor targetType = types.computeIfAbsent(type, TypeDescriptor::valueOf);
5765

core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringTypeConverterTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.camel.spring.boot;
1818

19+
import java.io.FileInputStream;
20+
import java.io.InputStream;
1921
import java.util.Arrays;
2022
import java.util.Collection;
2123
import java.util.List;
@@ -70,6 +72,19 @@ public void testConversionService() {
7072
Assertions.assertNull(converter.convertTo(String.class, source));
7173
}
7274

75+
@Test
76+
public void testStringToFileInputStreamConversionIsBlocked() {
77+
// Spring's ObjectToObjectConverter sees FileInputStream(String) constructor and
78+
// treats String content as a file path — must return null so Camel's own converters
79+
// handle String -> InputStream correctly
80+
Assertions.assertNull(converter.convertTo(FileInputStream.class, null, "some file content"));
81+
}
82+
83+
@Test
84+
public void testStringToInputStreamConversionIsBlocked() {
85+
Assertions.assertNull(converter.convertTo(InputStream.class, null, "some file content"));
86+
}
87+
7388
public static class Person {
7489
private String name;
7590
private int age;

0 commit comments

Comments
 (0)