Tencent/matrix · error · IllegalArgumentException
bad regex:
Error message
bad regex:
What it means
ExcludedBmps.BuilderWithParams.addClassNamePattern compiles the caller-supplied regex into a Pattern for class-name exclusion rules. A null or empty-string regex is rejected up front with IllegalArgumentException so Pattern.compile never receives invalid input at this point.
Solutions
- Pass a non-empty regex string to addClassNamePattern.
- Validate config-provided regexes before invoking the builder and skip empty entries.
- Default to a sensible pattern or omit the rule entirely when the config value is missing.
Example fix
// before
builder.addClassNamePattern(config.getClassNameRegex(), false);
// after
String regex = config.getClassNameRegex();
if (regex != null && !regex.isEmpty()) {
builder.addClassNamePattern(regex, false);
} Defensive patterns
Strategy: validation
Validate before calling
if (regex == null || regex.isEmpty()) { skipRule(); } else { builder.addClassNamePattern(regex, forGCRootOnly); } Try / catch
try { builder.addClassNamePattern(regex, false); } catch (IllegalArgumentException e) { log.warn("skipping empty regex rule"); } Prevention
- Validate config-sourced regexes before building exclusions
- Omit empty rules instead of passing empty strings
- Centralize exclusion-pattern construction in one validated helper
When it happens
Trigger: Calling addClassNamePattern(null, ...) or addClassNamePattern("", ...) while building the excluded-references/Bitmap exclusion configuration.
Common situations: Building exclusion config from external config files/remote parameters where the regex key is absent or empty; programmatic builder calls where a variable holding the pattern was never set.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- sizes should not be negative and maxSize should be 0 or…
- ---jobConfig can not be null!
- ---params can not be null!
- ---APK-FILE-PATH can not be null!
- ---'<config.getApkPath()>' is not exist!
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/7f5cb27360fab3cd.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-analyzer/src/main/java/com/tencent/matrix/resource/analyzer/model/ExcludedBmps.java:61
mClassNamePatterns = Collections.unmodifiableSet(builder.mClassNamePatterns);
}
public static Builder builder() {
return new BuilderWithParams();
}
public interface Builder extends ExcludedRefs.Builder {
Builder addClassNamePattern(String regex, boolean forGCRootOnly);
ExcludedBmps build();
}
static final class BuilderWithParams extends ExcludedRefs.BuilderWithParams implements Builder {
final Set<PatternInfo> mClassNamePatterns = new HashSet<>();
@Override
public Builder addClassNamePattern(String regex, boolean forGCRootOnly) {
if (regex == null || regex.length() == 0) {
throw new IllegalArgumentException("bad regex: " + regex);
}
mClassNamePatterns.add(new PatternInfo(Pattern.compile(regex), forGCRootOnly));
return this;
}
@Override
public ExcludedBmps build() {
return new ExcludedBmps(this);
}
}
}
View on GitHub (pinned to 3b8293bd65)