Skip to content

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

@namest504

Description

@namest504

In the QueryTransformers.CountSelectionTokenStream class, several .equals() calls are made with a variable on the left and a constant on the right (e.g., token.equals(CONSTANT)).

Example:

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

QueryTransformers.java
Before:

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

After:

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

While there is no evidence that token can currently be null, it is a widely accepted Java best practice to place
the constant or literal on the left side of an equals() comparison (e.g., CONSTANT.equals(token)).

This defensively prevents any potential NullPointerException if the code were to be refactored in the future in a
way that might allow a null variable.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions