theonedev/onedev · error · RuntimeException

Malformed pattern set

Error message

Malformed pattern set

What it means

PatternSet parses its pattern-set definition with an ANTLR grammar; a custom error listener replaces the default one and throws RuntimeException('Malformed pattern set') on any lexer/parser syntax error. This means the pattern-set text does not conform to the expected syntax (e.g. malformed include/exclude patterns, bad wildcards, stray characters).

Source

Thrown at server-core/src/main/java/io/onedev/server/util/patternset/PatternSet.java:87

    		files.add(new File(dir, path));
    	
		return files;
	}
	
	public static PatternSet parse(@Nullable String patternSetString) {
		Set<String> includes = new HashSet<>();
		Set<String> excludes = new HashSet<>();
		
		if (patternSetString != null) {
			CharStream is = CharStreams.fromString(patternSetString); 
			PatternSetLexer lexer = new PatternSetLexer(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 pattern set");
				}
				
			});
			CommonTokenStream tokens = new CommonTokenStream(lexer);
			PatternSetParser parser = new PatternSetParser(tokens);
			parser.removeErrorListeners();
			parser.setErrorHandler(new BailErrorStrategy());
			
			PatternsContext patternsContext = parser.patterns();
			
			for (PatternContext pattern: patternsContext.pattern()) {
				String value;
				if (pattern.Quoted() != null) 
					value = FenceAware.unfence(pattern.Quoted().getText());
				else 
					value = pattern.NQuoted().getText();
				value = StringUtils.unescape(value);
				if (pattern.Excluded() != null)

View on GitHub (pinned to d44925c47c)

Solutions

  1. Review the pattern-set string and fix syntax errors — use the supported glob forms (e.g. '**/*.java', 'docs/*') with correct include/exclude syntax.
  2. Simplify the pattern: remove unsupported constructs (regex-only syntax, triple stars, stray characters).
  3. Test the pattern incrementally: start with a simple valid pattern and add complexity until the failure reappears.
  4. Consult OneDev pattern-set documentation for the exact accepted grammar and rewrite the patterns accordingly.

Example fix

// before
String patterns = "src/**/*.java\n!**/*Test{,s}.java"; // brace expansion unsupported
// after
String patterns = "src/**/*.java\n!**/*Test.java\n!**/*Tests.java";
Defensive patterns

Strategy: validation

Validate before calling

boolean simplePatternOk(String patterns) {
    // basic sanity: no obviously unsupported constructs
    return patterns != null && !patterns.matches(".*(\\*\\*\\*|\\{).*") ;
}

Try / catch

try {
    PatternSet set = PatternSet.parse(patternText);
} catch (RuntimeException e) {
    if ("Malformed pattern set".equals(e.getMessage())) {
        // fall back to a safe default pattern set or surface config error
    } else throw e;
}

Prevention

When it happens

Trigger: Providing a pattern-set string (e.g. in file-matching/CI configuration) whose syntax the PatternSet grammar rejects — unbalanced characters, illegal wildcards like '***', malformed '**/' sequences, or stray separators in include/exclude lines.

Common situations: Hand-written glob patterns with unsupported syntax; pasting patterns from other tools (e.g. .gitignore or regex) that use constructs the pattern-set grammar does not accept; typos like missing '*' or stray spaces/quotes in the config field.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/ab583bf4dcff9c3d. Report an issue: GitHub.