OpenAPITools/openapi-generator · error · ParserException
Negation with no negated pattern.
Error message
Negation with no negated pattern.
What it means
IgnoreLineParser throws ParserException when a line in .openapi-generator-ignore consists of exactly '!' with nothing after it. '!' negates the pattern that follows; with no negated pattern the gitignore-style rule cannot be built, so parsing fails fast.
Source
Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/ignore/rules/IgnoreLineParser.java:69
StringBuilder sb = new StringBuilder();
String current = null;
String next = null;
char[] characters = text.toCharArray();
for (int i = 0, totalLength = characters.length; i < totalLength; i++) {
char character = characters[i];
current = String.valueOf(character);
next = i < totalLength - 1 ? String.valueOf(characters[i + 1]) : null;
if (i == 0) {
if ("#".equals(current)) {
//: A line starting with # serves as a comment.
parts.add(new Part(Token.COMMENT, text));
i = totalLength; // rather than early return
continue;
} else if ("!".equals(current)) {
if (i == totalLength - 1) {
throw new ParserException("Negation with no negated pattern.");
} else {
parts.add(new Part(Token.NEGATE));
continue;
}
} else if ("\\".equals(current) && "#".equals(next)) {
//: Put a backslash ("`\`") in front of the first hash for patterns
//: that begin with a hash.
// NOTE: Just push forward and drop the escape character. Falls through to TEXT token.
current = next;
next = null;
i++;
}
}
if (Token.MATCH_ANY.pattern.equals(current)) {
if (Token.MATCH_ANY.pattern.equals(next)) {
// peek ahead for invalid pattern. Slightly inefficient, but acceptable.View on GitHub (pinned to fcec517be3)
Solutions
- Delete the bare '!' line from .openapi-generator-ignore.
- Complete the negation if one was intended, e.g. '!/docs/README.md' to re-include a file ignored by a broader pattern.
- Scan the file for merge-conflict markers or truncated edits that left the line incomplete.
Example fix
# .openapi-generator-ignore (before): ! /docs/** # after: /docs/** !/docs/README.md
Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight: lint .openapi-generator-ignore before generation
import java.nio.file.*;
for (String line : Files.readAllLines(Paths.get(outputDir, ".openapi-generator-ignore"))) {
if (line.trim().equals("!"))
throw new IllegalStateException("Invalid ignore line '!' — negation with no pattern");
} Prevention
- Treat every '!' in .openapi-generator-ignore as incomplete until followed by a pattern.
- Add the ignore file to lint/pre-commit checks in repos that regenerate code.
- Resolve git merge conflicts in .openapi-generator-ignore completely; leftover fragments often produce bare '!' lines.
When it happens
Trigger: The .openapi-generator-ignore file in the output directory contains a line whose only character is '!' (the parser checks i == totalLength - 1 at position 0). Parsing of the ignore file aborts and generation stops.
Common situations: Hand-editing the ignore file and leaving a stray '!'; git merge-conflict leftovers; misunderstanding the syntax by assuming a lone '!' flips the default ignore behavior.
Related errors
- The pattern *** is invalid.
- Failed to generate .openapi-generator-ignore when the option
- Could not generate supporting file '{ignoreFileNameTarget}'
AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22).
Data as JSON: /api/errors/78460e177bbbdfca.
Report an issue: GitHub.