Skip to content

ReactiveExtensionAwareEvaluationContextProvider throws java.lang.IllegalStateException: Unsupported extension type: org.springframework.data.jpa.repository.support.JpaEvaluationContextExtension #2392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dsbecker opened this issue Jun 24, 2021 · 0 comments
Assignees
Labels
type: bug A general bug

Comments

@dsbecker
Copy link
Contributor

dsbecker commented Jun 24, 2021

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!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 24, 2021
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 28, 2021
@mp911de mp911de self-assigned this Jun 28, 2021
@mp911de mp911de added this to the 2.4.11 (2020.0.11) milestone Jul 12, 2021
mp911de pushed a commit that referenced this issue Jul 12, 2021
…onAwareEvaluationContextProvider.

Using JpaEvaluationContextExtension with reactive infrastructure in place, ReactiveExtensionAwareEvaluationContextProvider can lead to IllegalStateException if the desired extension doesn't match the predicate instead of being silently dropped.

Closes #2392
Original pull request: #2393.
mp911de added a commit that referenced this issue Jul 12, 2021
Add unit tests.

See #2392
Original pull request: #2393.
mp911de added a commit that referenced this issue Jul 12, 2021
Add unit tests.

See #2392
Original pull request: #2393.
mp911de pushed a commit that referenced this issue Jul 12, 2021
…onAwareEvaluationContextProvider.

Using JpaEvaluationContextExtension with reactive infrastructure in place, ReactiveExtensionAwareEvaluationContextProvider can lead to IllegalStateException if the desired extension doesn't match the predicate instead of being silently dropped.

Closes #2392
Original pull request: #2393.
mp911de added a commit that referenced this issue Jul 12, 2021
Add unit tests.

See #2392
Original pull request: #2393.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants