{"record":{"id":"98bdf4c29b60c1ab","repo":"apereo/cas","slug":"pattern-cannot-be-null-blank","errorCode":null,"errorMessage":"Pattern cannot be null/blank","messagePattern":"Pattern cannot be null/blank","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/RegexUtils.java","lineNumber":93,"sourceCode":"     *\n     * @param pattern the pattern, may not be null.\n     * @return the pattern or {@link RegexUtils#MATCH_NOTHING_PATTERN}\n     * if pattern is null or invalid.\n     */\n    public static Pattern createPattern(@Nullable final String pattern) {\n        return createPattern(pattern, Pattern.CASE_INSENSITIVE);\n    }\n\n    /**\n     * Creates the pattern with the given flags.\n     *\n     * @param pattern the pattern, may be null.\n     * @param flags   the flags\n     * @return the compiled pattern or {@link RegexUtils#MATCH_NOTHING_PATTERN} if pattern is null or invalid.\n     */\n    public static Pattern createPattern(@Nullable final String pattern, final int flags) {\n        if (StringUtils.isBlank(pattern)) {\n            LOGGER.warn(\"Pattern cannot be null/blank\");\n            return MATCH_NOTHING_PATTERN;\n        }\n        try {\n            return computePattern(pattern, flags);\n        } catch (final PatternSyntaxException exception) {\n            LOGGER.debug(\"Pattern [{}] is not a valid regex.\", pattern);\n            return MATCH_NOTHING_PATTERN;\n        }\n    }\n\n    /**\n     * Matches the entire region for the string.\n     *\n     * @param pattern the pattern\n     * @param value   the string\n     * @return true/false\n     * @see Matcher#matches()\n     */","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/apereo/cas/blob/e7288fc434b4f4505b8452e1a57e8fb3111bb863/core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/RegexUtils.java#L75-L111","documentation":"RegexUtils.createPattern(String, int) is null-tolerant by design: when the given pattern string is null or blank it logs a warning and returns MATCH_NOTHING_PATTERN (a regex that matches nothing) instead of throwing a NullPointerException. This lets CAS configuration omit optional regex settings safely, but callers who expected a real pattern will see all matches fail silently.","triggerScenarios":"Passing null, empty, or whitespace-only strings to RegexUtils.createPattern(...), typically from a cas.* regex configuration property that was left unset or cleared. Invalid regexes take a different path (debug log + MATCH_NOTHING_PATTERN after PatternSyntaxException).","commonSituations":"A regex-based service attribute filter or access strategy property left blank in config; an installer not prompting for an optional pattern; property placeholder resolving to empty string.","solutions":["Provide a valid regex value for the configuration property that feeds createPattern","If the pattern is genuinely optional, code defensively against MATCH_NOTHING_PATTERN semantics (no matches) rather than treating absence as 'match all'","Check for placeholder/variable resolution that silently yields an empty string (e.g. ${VAR} with VAR unset)"],"exampleFix":"// before (yml)\ncas:\n  authn:\n    pattern: \"\"   # results in MATCH_NOTHING_PATTERN\n// after\ncas:\n  authn:\n    pattern: \"^(user1|user2)$\"","handlingStrategy":"validation","validationCode":"String pattern = properties.getPattern();\nif (pattern == null || pattern.isBlank()) {\n    throw new IllegalArgumentException(\"pattern property must be a non-blank regex\");\n}\nPattern compiled = RegexUtils.createPattern(pattern);","typeGuard":"static boolean isUsablePattern(String p) {\n    return p != null && !p.isBlank() && RegexUtils.createPattern(p) != RegexUtils.MATCH_NOTHING_PATTERN;\n}","tryCatchPattern":null,"preventionTips":["Never leave regex-based cas.* properties blank when the feature depends on matching","Remember createPattern is fail-open: blank/invalid means 'match nothing', not 'match everything'","Validate config at deploy time (grep for empty regex values) rather than at runtime"],"tags":["regex","configuration","null-value"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"e7288fc434b4f4505b8452e1a57e8fb3111bb863","analyzedAt":"2026-09-08T15:39:16.015Z","contentChangedAt":"2026-09-08T15:39:16.015Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}