{"record":{"id":"e73fad23935cbcd5","repo":"apache/cassandra","slug":"output-file-name-must-match-pattern-s","errorCode":null,"errorMessage":"Output file name must match pattern %s.","messagePattern":"Output file name must match pattern (.+?)\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/AsyncProfilerService.java","lineNumber":397,"sourceCode":"            {\n                return asyncProfiler.execute(\"status\");\n            }\n        });\n    }\n\n    @Override\n    public synchronized boolean isEnabled()\n    {\n        return instance != null && asyncProfiler != null;\n    }\n\n    public static String validateOutputFileName(String outputFile)\n    {\n        if (outputFile == null || outputFile.trim().isEmpty())\n            throw new IllegalArgumentException(\"Output file name must not be null or empty.\");\n\n        if (!VALID_FILENAME_REGEX_PATTERN.matcher(outputFile).matches())\n            throw new IllegalArgumentException(format(\"Output file name must match pattern %s.\", VALID_FILENAME_REGEX_PATTERN));\n\n        return outputFile;\n    }\n\n    public static String validateCommand(String command)\n    {\n        if (command == null || command.isBlank())\n            throw new IllegalArgumentException(\"Command can not be null or blank string.\");\n\n        return command;\n    }\n\n    /**\n     * @param duration duration of profiling\n     * @return converted string representation of duration to seconds\n     */\n    public static int parseDuration(String duration)\n    {","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/AsyncProfilerService.java#L379-L415","documentation":"validateOutputFileName enforces VALID_FILENAME_REGEX_PATTERN so profiler output stays inside the profiles log directory and cannot contain path separators or illegal characters. A file name that is non-empty but does not match the allowed pattern (e.g. containing '/', '..', or special characters) triggers this IllegalArgumentException.","triggerScenarios":"Calling file()/apply() with names containing path separators, dots-segments, spaces or other characters disallowed by the regex — anything that could escape the log dir or break file creation.","commonSituations":"Users passing absolute paths or subdirectory paths as the output name; names generated with timestamps in unexpected formats; cross-platform path separators.","solutions":["Use a simple base file name matching the documented pattern (letters, digits, '-', '_', '.') with no slashes","Strip any directory components and pass only the base name","Prevalidate locally with the same regex shown in the exception message before calling"],"exampleFix":"// before\nservice.apply(\"start\", \"/tmp/prof/results.html\");\n// after\nservice.apply(\"start\", \"results.html\");","handlingStrategy":"validation","validationCode":"java.util.regex.Pattern P = AsyncProfilerService.VALID_FILENAME_REGEX_PATTERN; // mirror locally\nif (outputFile == null || !P.matcher(outputFile).matches()) throw new IllegalArgumentException(\"bad output file name\");","typeGuard":null,"tryCatchPattern":"try { svc.apply(cmd, name); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"must match pattern\")) { name = name.replaceAll(\"[^A-Za-z0-9._-]\", \"_\"); svc.apply(cmd, name); } else throw e; }","preventionTips":["Use only simple base names: letters, digits, dot, dash, underscore","Never include directory separators or absolute paths","Sanitize generated names (timestamps etc.) against the pattern"],"tags":["validation","regex","filename"],"backgroundTag":"invalid-identifier-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}