Skip to content

Commit dd0848b

Browse files
committed
DATACMNS-1484 - Fixed too aggressive conversion to Streamable in IterableToStreamableConverter.
We now explicitly check for the target type to be assignable to Streamable to opt into conversion. Without that check, every collection returned from a method declaring Iterable as return type would've been converted into a Streamable by accident. Related ticket: DATACMNS-1430.
1 parent d12801a commit dd0848b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,10 @@ public Set<ConvertiblePair> getConvertibleTypes() {
699699
@Override
700700
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
701701

702+
if (sourceType.isAssignableTo(targetType)) {
703+
return false;
704+
}
705+
702706
if (!Iterable.class.isAssignableFrom(sourceType.getType())) {
703707
return false;
704708
}

src/test/java/org/springframework/data/repository/util/QueryExecutionConvertersUnitTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,15 @@ public void convertsToStreamableWrapperImplementingStreamable() throws Exception
355355
.containsExactly("foo");
356356
}
357357

358+
@Test // DATACMNS-1484
359+
public void doesNotConvertCollectionToStreamableIfReturnTypeIsIterable() {
360+
361+
List<String> source = Arrays.asList("1", "2");
362+
363+
assertThat(conversionService.convert(source, Iterable.class)).isSameAs(source);
364+
365+
}
366+
358367
interface Sample {
359368

360369
Page<String> pages();

0 commit comments

Comments
 (0)