apple/pkl · error · InvalidGlobPatternException
invalidGlobInvalidCharacterInCharacterClass
invalidGlobInvalidCharacterInCharacterClass
Error message
invalidGlobInvalidCharacterInCharacterClass
What it means
A glob character class `[...]` must not contain `/` because character classes match a single path component and cannot cross directory boundaries. consumeCharacterClass throws InvalidGlobPatternException with this code when `/` appears inside a class.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java:124
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 {
sb.append(current);
}
i++;
if (i == globPattern.length()) {
throw new InvalidGlobPatternException(
ErrorMessages.create("invalidGlobMissingCharacterClassTerminator"));
}
current = globPattern.charAt(i);
}
sb.append("]]");
return i;
}
public static Pattern toRegexPattern(String globPattern) throws InvalidGlobPatternException {View on GitHub (pinned to f3efcbfc9b)
Solutions
- Remove `/` from the character class; move path separators outside the class (e.g. `[ab]/c` instead of `[a/b]/c`).
- Use a `{a,b}` alternation group to match alternative path segments.
- Split the pattern into separate globs if needed.
Example fix
// before
glob = "[a/b]/config.pkl"
// after
glob = "{a,b}/config.pkl" Defensive patterns
Strategy: validation
Validate before calling
java.util.regex.Matcher m = java.util.regex.Pattern.compile("\\[[^\\]]*/[^\\]]*\\]").matcher(glob);
if (m.find()) throw new IllegalArgumentException("'/' not allowed inside glob character class");
Try / catch
try { return GlobResolver.toRegexPattern(glob); } catch (InvalidGlobPatternException e) { throw new IllegalArgumentException("Invalid character class in: " + glob, e); }
Prevention
- Keep `/` outside character classes.
- Use {a,b} alternation for alternative path segments.
- Review hand-edited patterns for stray slashes.
When it happens
Trigger: Writing a glob like `src/[a/b].pkl` or `**/[ab/c]` — any `/` between an opening `[` and its closing `]` passed to GlobResolver.toRegexString/toRegexPattern.
Common situations: Trying to match either of two directory paths inside a class; misunderstanding that `[a/b]` means 'a or b directory'; hand-editing patterns and accidentally inserting a slash.
Related errors
- invalidGlobMissingCharacterClassTerminator
- invalidGlobPattern
- invalidGlobPattern
- invalidGlobUnsupportedFeature
- invalidGlobNestedSubpattern
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/526a24d6cab72e88.
Report an issue: GitHub.