Skip to content

Limit::equals can throw an exception #3023

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
sirpi opened this issue Jan 12, 2024 · 1 comment
Closed

Limit::equals can throw an exception #3023

sirpi opened this issue Jan 12, 2024 · 1 comment
Assignees
Labels
in: repository Repositories abstraction type: bug A general bug

Comments

@sirpi
Copy link

sirpi commented Jan 12, 2024

import org.springframework.data.domain.Limit;

Limit limited = Limit.of(5);
Limit unlimited = Limit.unlimited();

limited.equals(unlimited);

The above code throws an IllegalStateException with message "Unlimited does not define 'max'. Please check 'isLimited' before attempting to read 'max'". It is caused by the incomplete equals method where this case is not handled (this: limited, that: unlimited).

Fix:

if (this.isUnlimited() && that.isUnlimited()) {
				return true;
			}

must be replaced with

if (that.isUnlimited()) {
				return false;
			}

(this.isUnlimited() is always false anyway)

u.i.: I found this in a unit test where multiple queries were mocked and the Query::equals called Limit::equals in the background, causing some tests fail.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 12, 2024
odrotbohm added a commit that referenced this issue Jan 12, 2024
odrotbohm added a commit that referenced this issue Jan 12, 2024
odrotbohm added a commit that referenced this issue Jan 12, 2024
@odrotbohm
Copy link
Member

That's fixed now.

@odrotbohm odrotbohm added type: bug A general bug in: repository Repositories abstraction and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 12, 2024
@odrotbohm odrotbohm added this to the 3.2.3 (2023.1.3) milestone Jan 12, 2024
@odrotbohm odrotbohm self-assigned this Jan 12, 2024
odrotbohm added a commit that referenced this issue Jan 12, 2024
odrotbohm added a commit that referenced this issue Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository Repositories abstraction type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants