{"record":{"id":"7f5cb27360fab3cd","repo":"Tencent/matrix","slug":"bad-regex","errorCode":null,"errorMessage":"bad regex: ","messagePattern":"bad regex: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-analyzer/src/main/java/com/tencent/matrix/resource/analyzer/model/ExcludedBmps.java","lineNumber":61,"sourceCode":"        mClassNamePatterns = Collections.unmodifiableSet(builder.mClassNamePatterns);\n    }\n\n    public static Builder builder() {\n        return new BuilderWithParams();\n    }\n\n    public interface Builder extends ExcludedRefs.Builder {\n        Builder addClassNamePattern(String regex, boolean forGCRootOnly);\n        ExcludedBmps build();\n    }\n\n    static final class BuilderWithParams extends ExcludedRefs.BuilderWithParams implements Builder {\n        final Set<PatternInfo> mClassNamePatterns = new HashSet<>();\n\n        @Override\n        public Builder addClassNamePattern(String regex, boolean forGCRootOnly) {\n            if (regex == null || regex.length() == 0) {\n                throw new IllegalArgumentException(\"bad regex: \" + regex);\n            }\n            mClassNamePatterns.add(new PatternInfo(Pattern.compile(regex), forGCRootOnly));\n            return this;\n        }\n\n        @Override\n        public ExcludedBmps build() {\n            return new ExcludedBmps(this);\n        }\n    }\n}\n","sourceCodeStart":43,"sourceCodeEnd":73,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-analyzer/src/main/java/com/tencent/matrix/resource/analyzer/model/ExcludedBmps.java#L43-L73","documentation":"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.","triggerScenarios":"Calling addClassNamePattern(null, ...) or addClassNamePattern(\"\", ...) while building the excluded-references/Bitmap exclusion configuration.","commonSituations":"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.","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."],"exampleFix":"// before\nbuilder.addClassNamePattern(config.getClassNameRegex(), false);\n// after\nString regex = config.getClassNameRegex();\nif (regex != null && !regex.isEmpty()) {\n    builder.addClassNamePattern(regex, false);\n}","handlingStrategy":"validation","validationCode":"if (regex == null || regex.isEmpty()) { skipRule(); } else { builder.addClassNamePattern(regex, forGCRootOnly); }","typeGuard":null,"tryCatchPattern":"try { builder.addClassNamePattern(regex, false); } catch (IllegalArgumentException e) { log.warn(\"skipping empty regex rule\"); }","preventionTips":["Validate config-sourced regexes before building exclusions","Omit empty rules instead of passing empty strings","Centralize exclusion-pattern construction in one validated helper"],"tags":["regex","configuration","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}