{"record":{"id":"28865c919a2f3034","repo":"apache/cassandra","slug":"output-file-name-must-not-be-null-or-empty","errorCode":null,"errorMessage":"Output file name must not be null or empty.","messagePattern":"Output file name must not be null or empty\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/AsyncProfilerService.java","lineNumber":394,"sourceCode":"        {\n            @Override\n            public String apply(AsyncProfiler asyncProfiler) throws Throwable\n            {\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","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/AsyncProfilerService.java#L376-L412","documentation":"validateOutputFileName is a static guard applied by the file() and apply() entry points. It rejects null or whitespace-only output file names before any profiler work starts, because async-profiler needs a concrete target file for its output.","triggerScenarios":"Calling apply(cmd, outputFile) or setting the output file via file(...) with null, \"\", or a blank/whitespace-only string (e.g. from an unset config value).","commonSituations":"Config keys for the profiler output file left unset; scripting that interpolates an empty variable into the file name; JMX clients sending empty strings.","solutions":["Provide a non-empty file name such as 'cassandra-profiling-results.html'","Trim and check the value in tooling before invoking the MBean","Fall back to a default name when the configured value is blank"],"exampleFix":"// before\nservice.apply(\"start\", cfg.get(\"profiler.output\")); // null\n// after\nString out = cfg.getOrDefault(\"profiler.output\", \"async-profiler.html\").trim();\nif (!out.isEmpty()) service.apply(\"start\", out);","handlingStrategy":"validation","validationCode":"if (outputFile == null || outputFile.trim().isEmpty()) throw new IllegalArgumentException(\"output file name required\");","typeGuard":"boolean isValidOutputName(String s) { return s != null && !s.trim().isEmpty(); }","tryCatchPattern":"try { svc.apply(cmd, file); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"must not be null or empty\")) { svc.apply(cmd, \"async-profiler.html\"); } else throw e; }","preventionTips":["Validate config-driven file names at startup","Apply .trim() before passing names","Provide default output file names in tooling"],"tags":["validation","null","async-profiler"],"backgroundTag":"empty-required-field","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}