diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java index cf135d08ed..8d2c0d2a3e 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java @@ -966,7 +966,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { if (desiredTokenKind == TokenKind.IDENTIFIER) { // Might be one of the textual forms of the operators (e.g. NE for != ) - // in which case we can treat it as an identifier. The list is represented here: - // Tokenizer.alternativeOperatorNames and those ones are in order in the TokenKind enum. + // Tokenizer.ALTERNATIVE_OPERATOR_NAMES and those ones are in order in the TokenKind enum. if (t.kind.ordinal() >= TokenKind.DIV.ordinal() && t.kind.ordinal() <= TokenKind.NOT.ordinal() && t.data != null) { // if t.data were null, we'd know it wasn't the textual form, it was the symbol form diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/Tokenizer.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/Tokenizer.java index 5ca7b3c30c..8d80fc8a33 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/Tokenizer.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/Tokenizer.java @@ -35,7 +35,14 @@ import org.springframework.expression.spel.SpelParseException; */ class Tokenizer { - // If this gets changed, it must remain sorted... + /** + * Alternative textual operator names which must match enum constant names + * in {@link TokenKind}. + *

Note that {@code AND} and {@code OR} are also alternative textual + * names, but they are handled later in {@link InternalSpelExpressionParser}. + *

If this list gets changed, it must remain sorted since we use it with + * {@link Arrays#binarySearch(Object[], Object)}. + */ private static final String[] ALTERNATIVE_OPERATOR_NAMES = {"DIV", "EQ", "GE", "GT", "LE", "LT", "MOD", "NE", "NOT"}; @@ -448,8 +455,8 @@ class Tokenizer { char[] subarray = subarray(start, this.pos); // Check if this is the alternative (textual) representation of an operator (see - // alternativeOperatorNames) - if ((this.pos - start) == 2 || (this.pos - start) == 3) { + // ALTERNATIVE_OPERATOR_NAMES). + if (subarray.length == 2 || subarray.length == 3) { String asString = new String(subarray).toUpperCase(); int idx = Arrays.binarySearch(ALTERNATIVE_OPERATOR_NAMES, asString); if (idx >= 0) {