Description
When a ReactiveMongoRepository
uses an @Query
annotation, I get a java.lang.IllegalStateException: Unsupported extension type: org.springframework.data.jpa.repository.support.JpaEvaluationContextExtension
thrown by ReactiveExtensionAwareEvaluationContextProvider
after upgrading to spring-data-commons 2.4x+. It appears that the if (it instanceof EvaluationContextExtension) {
clause is missing a return Mono.empty();
when extensionFilter.test(information)
returns false like if (it instanceof ReactiveEvaluationContextExtension) {
has. This allows it to fall through and return the Mono.error(...)
.
Example Repository: (this is an artificially simple example)
import com.example.MyObject
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
import reactor.core.publisher.Flux;
public interface MyObjectRepository extends ReactiveMongoRepository<MyObject, String> {
@Query(value = "{ someField: ?0 }")
Flux<MyObject> findAllBySomeField(String someField);
}
This can be fixed by modifying ReactiveExtensionAwareEvaluationContextProvider.getExtensions(...)
as follows:
@SuppressWarnings({ "unchecked", "rawtypes" })
private Mono<List<EvaluationContextExtension>> getExtensions(
Predicate<EvaluationContextExtensionInformation> extensionFilter) {
Collection<? extends ExtensionIdAware> extensions = evaluationContextProvider.getExtensions();
return Flux.fromIterable(extensions).concatMap(it -> {
if (it instanceof EvaluationContextExtension) {
EvaluationContextExtension extension = (EvaluationContextExtension) it;
EvaluationContextExtensionInformation information = evaluationContextProvider.getOrCreateInformation(extension);
if (extensionFilter.test(information)) {
return Mono.just(extension);
}
return Mono.empty();
}
if (it instanceof ReactiveEvaluationContextExtension) {
ReactiveEvaluationContextExtension extension = (ReactiveEvaluationContextExtension) it;
ResolvableType actualType = getExtensionType(it);
if (actualType.equals(ResolvableType.NONE) || actualType.isAssignableFrom(GENERIC_EXTENSION_TYPE)) {
return extension.getExtension();
}
EvaluationContextExtensionInformation information = evaluationContextProvider
.getOrCreateInformation((Class) actualType.getRawClass());
if (extensionFilter.test(information)) {
return extension.getExtension();
}
return Mono.empty();
}
return Mono.error(new IllegalStateException("Unsupported extension type: " + it));
}).collectList();
}
I will submit a simple PR for it. This is my first report and PR to this project, please be kind.
Thank you!