Fix error when using the message operator with regex on old index version
The regex support for the 'message' operator requires the 'messageexact'
field to be present in the change index version. If the change index
version is old and misses the 'messageexact' field the user got the
following error:
'messageexact' operator is not supported by change index version
This message is confusing since the user used the 'message' operator and
a 'messageexact' operator doesn't exist (it's an internal field name,
not an operator).
With this change the error message is now changed to:
'message' operator with regular expression is not supported by change
index version
The support for regex in the 'message' operator was implemented by
change Ic33c935fe.
Release-Notes: skip
Bug: Google b/264478714
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Ifeb745135c6f4652c57a59026ccf436d03a618bb
diff --git a/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java b/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java
index 24d205d..0a39bbf 100644
--- a/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java
+++ b/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java
@@ -1140,7 +1140,10 @@
@Operator
public Predicate<ChangeData> message(String text) throws QueryParseException {
if (text.startsWith("^")) {
- checkFieldAvailable(ChangeField.COMMIT_MESSAGE_EXACT, "messageexact");
+ if (!args.index.getSchema().hasField(ChangeField.COMMIT_MESSAGE_EXACT)) {
+ throw new QueryParseException(
+ "'message' operator with regular expression is not supported by change index version");
+ }
return new RegexMessagePredicate(text);
}
return ChangePredicates.message(text);