Skip to content

QuerydslPredicateBuilder (still) returns null Predicate [DATACMNS-1398] #1833

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
spring-projects-issues opened this issue Sep 28, 2018 · 1 comment
Assignees
Labels
status: superseded An issue that has been superseded by another

Comments

@spring-projects-issues
Copy link

Lars van der Vliet opened DATACMNS-1398 and commented

For issue https://jira.spring.io/browse/DATACMNS-1168 a check is added to prevent the 

getPredicate method to return null. The method will actually still return null when unrelated (to the entity) query params are used in the URL.

for example calling the following url /api/test results in correct behavior, but when calling /api/test?idontexistasproperty=true will result in a "null" Predicate in the controller method.

Proposed fix:

 

	@Nullable
	public Predicate getPredicate(TypeInformation<?> type, MultiValueMap<String, String> values,
			QuerydslBindings bindings) {


		Assert.notNull(bindings, "Context must not be null!");


		BooleanBuilder builder = new BooleanBuilder();


		if (values.isEmpty()) {
			return builder;
		}


		for (Entry<String, List<String>> entry : values.entrySet()) {


			if (isSingleElementCollectionWithoutText(entry.getValue())) {
				continue;
			}


			String path = entry.getKey();


			if (!bindings.isPathAvailable(path, type)) {
				continue;
			}


			PathInformation propertyPath = bindings.getPropertyPath(path, type);


			if (propertyPath == null) {
				continue;
			}


			Collection<Object> value = convertToPropertyPathSpecificType(entry.getValue(), propertyPath);
			Optional<Predicate> predicate = invokeBinding(propertyPath, bindings, value);


			predicate.ifPresent(builder::and);
		}

                // return builder when it doens't have a value
		return builder.hasValue() ? builder.getValue() : builder;
	}

 


Affects: 2.0.10 (Kay SR10), 2.1 GA (Lovelace)

@spring-projects-issues spring-projects-issues added the type: bug A general bug label Dec 30, 2020
@mp911de mp911de added status: superseded An issue that has been superseded by another and removed type: bug A general bug labels Mar 21, 2023
@mp911de
Copy link
Member

mp911de commented Mar 21, 2023

That has been fixed recently via #2396

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

3 participants