{"record":{"id":"5c475a315b1c44f1","repo":"apache/cassandra","slug":"command-can-not-be-null-or-blank-string","errorCode":null,"errorMessage":"Command can not be null or blank string.","messagePattern":"Command can not be null or blank string\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/AsyncProfilerService.java","lineNumber":405,"sourceCode":"    {\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    {\n        int durationSeconds = new DurationSpec.IntSecondsBound(duration).toSeconds();\n        if (durationSeconds > MAX_SAFE_PROFILING_DURATION)\n            throw new IllegalArgumentException(format(\"Max profiling duration is %s seconds. If you need longer profiling, use execute command instead.\",\n                                                      MAX_SAFE_PROFILING_DURATION));\n        return durationSeconds;\n    }\n\n    private static void maybeCreateProfilesLogDir()","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/AsyncProfilerService.java#L387-L423","documentation":"validateCommand (invoked by apply) rejects null or blank raw async-profiler command strings. The apply() path forwards the command text to the profiler agent, so an empty command would be meaningless and is rejected up front.","triggerScenarios":"Calling apply(null, outputFile) or apply(\" \", outputFile); building the command string from an empty config/template variable.","commonSituations":"Scripting where the command template failed to render; JMX clients sending whitespace; refactors that dropped the default 'start'/'stop' command.","solutions":["Pass a real async-profiler command such as 'start', 'stop', or 'status'","Check the string is not blank before invoking apply","Restore a default command in tooling when none is configured"],"exampleFix":"// before\nservice.apply(cmdTemplate, file); // cmdTemplate == \"\"\n// after\nString cmd = cmdTemplate == null || cmdTemplate.isBlank() ? \"start\" : cmdTemplate;\nservice.apply(cmd, file);","handlingStrategy":"validation","validationCode":"if (command == null || command.isBlank()) throw new IllegalArgumentException(\"async-profiler command required\");","typeGuard":"boolean isValidCommand(String c) { return c != null && !c.isBlank(); }","tryCatchPattern":"try { svc.apply(cmd, file); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"null or blank\")) { svc.apply(\"start\", file); } else throw e; }","preventionTips":["Default to 'start'/'stop'/'status' commands when templating fails","Assert command non-blank in scripts before JMX calls","Avoid building commands from optional config values without fallbacks"],"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"}