Skip to content

Conversation

namest504
Copy link

#4047

Refactors QueryTransformers to use constant-first equals() calls. This is a common best practice to prevent potential NullPointerExceptions if the variable (token) were to be null.

class QueryTokens {
    // ...
    static final QueryToken TOKEN_COMMA = token(", ");
    static final QueryToken TOKEN_AS = expression("AS");
    // ...
}

Before:

if (token.equals(TOKEN_AS)) {
     // ...
 }

After:

if (TOKEN_AS.equals(token)) {
    // ...
}
  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 17, 2025
@mp911de mp911de added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 20, 2025
@mp911de
Copy link
Member

mp911de commented Oct 20, 2025

This is a common best practice to prevent potential NullPointerExceptions if the variable (token) were to be null.

We have proper indication of nullable parameters and whether collections contain nullable elements hence we don't need to address an aspect that isn't broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor QueryTransformers to use constant-first equals for improved null safety

3 participants