apple/pkl · error · InvalidGlobPatternException

invalidGlobMissingCharacterClassTerminator

invalidGlobMissingCharacterClassTerminator

Error message

invalidGlobMissingCharacterClassTerminator

What it means

When converting a glob pattern to a regex, a character class `[...]` must be terminated by `]`. consumeCharacterClass throws InvalidGlobPatternException with this code if the input ends (NULL sentinel) before the class is closed.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java:110

    var i = idx;
    switch (getNextChar(globPattern, i)) {
      case '^' -> {
        // verbatim; escape
        sb.append("\\^");
        i++;
      }
      case '!' -> {
        // negation
        sb.append("^");
        i++;
      }
      case ']' -> {
        // the first `]` in a character class is verbatim and not treated as a closing delimiter.
        sb.append(']');
        i++;
      }
      case NULL ->
          throw new InvalidGlobPatternException(
              ErrorMessages.create("invalidGlobMissingCharacterClassTerminator"));
    }
    i++;
    var current = globPattern.charAt(i);
    while (current != ']') {
      if (current == '[') {
        var next = getNextChar(globPattern, i);
        if (next == ':' || next == '=' || next == '.') {
          throw new InvalidGlobPatternException(
              ErrorMessages.create("invalidGlobUnsupportedFeature"));
        }
      }
      if (current == '/') {
        throw new InvalidGlobPatternException(
            ErrorMessages.create("invalidGlobInvalidCharacterInCharacterClass", current));
      } else if (current == '\\') {
        sb.append("\\\\");
      } else {

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Add the missing closing `]` to the character class in the glob pattern.
  2. Validate the glob pattern syntax before passing it to the resolver.
  3. Escape a literal `[` if a character class was not intended.

Example fix

// before
glob = "src/[abc"
// after
glob = "src/[abc]"
Defensive patterns

Strategy: validation

Validate before calling

boolean hasBalancedBrackets(String glob) {
  int open = 0;
  for (char c : glob.toCharArray()) { if (c == '[') open++; if (c == ']' && open > 0) open--; }
  return open == 0;
}

Try / catch

try { pattern = GlobResolver.toRegexPattern(glob); } catch (InvalidGlobPatternException e) { throw new IllegalArgumentException("Bad glob: " + glob, e); }

Prevention

When it happens

Trigger: Passing a glob pattern with an unterminated character class to GlobResolver.toRegexString/toRegexPattern, e.g. `src/[abc` with no closing `]`.

Common situations: Typos in glob patterns in project config (exclude/include lists); patterns built by string concatenation where the closing bracket was dropped; user-supplied ignore patterns.

Related errors


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/49466e9caa168e36. Report an issue: GitHub.