theonedev/onedev · error · RuntimeException
Malformed user match
Error message
Malformed user match
What it means
UserMatch.parse builds an ANTLR lexer with a custom BaseErrorListener; any lexical/syntax failure in the user match string is rethrown as RuntimeException 'Malformed user match'. The expression violates the UserMatch grammar and cannot be tokenized into valid criteria.
Source
Thrown at server-core/src/main/java/io/onedev/server/util/usermatch/UserMatch.java:99
} else {
throw new ExplicitException("Unrecognized user match criteria");
}
}
public static UserMatch parse(@Nullable String userMatchString) {
List<UserMatchCriteria> criterias = new ArrayList<>();
List<UserMatchCriteria> exceptCriterias = new ArrayList<>();
if (userMatchString != null) {
CharStream is = CharStreams.fromString(userMatchString);
UserMatchLexer lexer = new UserMatchLexer(is);
lexer.removeErrorListeners();
lexer.addErrorListener(new BaseErrorListener() {
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
int charPositionInLine, String msg, RecognitionException e) {
throw new RuntimeException("Malformed user match");
}
});
CommonTokenStream tokens = new CommonTokenStream(lexer);
UserMatchParser parser = new UserMatchParser(tokens);
parser.removeErrorListeners();
parser.setErrorHandler(new BailErrorStrategy());
UserMatchContext userMatchContext = parser.userMatch();
for (CriteriaContext criteriaContext: userMatchContext.criteria())
criterias.add(getUserMatchCriteria(criteriaContext));
for (ExceptCriteriaContext exceptCriteriaContext: userMatchContext.exceptCriteria()) {
exceptCriterias.add(getUserMatchCriteria(exceptCriteriaContext.criteria()));
}
}
View on GitHub (pinned to d44925c47c)
Solutions
- Correct the match expression syntax (quote names, balance parentheses)
- Inspect the stored string for stripped quotes or stray characters from templating/shell
- Catch RuntimeException around parse and show a syntax-error message before saving
Example fix
// before
userMatchString = "user:bob and (";
// after
userMatchString = "user:bob"; Defensive patterns
Strategy: validation
Validate before calling
try {
UserMatch.parse(matchString);
} catch (RuntimeException e) {
throw new ExplicitException("Invalid user match: " + matchString);
} Try / catch
try {
UserMatch.parse(matchString);
} catch (RuntimeException e) {
log.error("Malformed user match: {}", matchString, e);
} Prevention
- Keep match expressions simple and quote names with special chars
- Watch for shell/YAML quoting stripping quotes
- Parse-validate at settings-save time rather than at use time
When it happens
Trigger: Parsing a user match string with unbalanced quotes/parentheses or invalid tokens, e.g. 'user:bob and (' or a stray semicolon.
Common situations: Hand-edited match settings; shell/YAML quoting stripping quotes; copy-paste introducing invisible characters.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/23a7ab37559dfeea.
Report an issue: GitHub.