{"record":{"id":"fe68bc93a39dddd0","repo":"apache/dolphinscheduler","slug":"run-java-task-error","errorCode":null,"errorMessage":"run java task error","messagePattern":"run java task error","errorType":"exception","errorClass":"TaskException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/main/java/org/apache/dolphinscheduler/plugin/task/java/JavaTask.java","lineNumber":125,"sourceCode":"                    .appendScript(command);\n            TaskResponse taskResponse = shellCommandExecutor.run(shellActuatorBuilder, taskCallBack);\n            log.info(\"java task run result: {}\", taskResponse);\n            setExitStatusCode(taskResponse.getExitStatusCode());\n            setAppIds(taskResponse.getAppIds());\n            setProcessId(taskResponse.getProcessId());\n            setTaskOutputParams(shellCommandExecutor.getTaskOutputParams());\n        } catch (InterruptedException e) {\n            log.error(\"java task interrupted \", e);\n            setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE);\n            Thread.currentThread().interrupt();\n        } catch (RunTypeNotFoundException e) {\n            log.error(e.getMessage());\n            setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE);\n            throw e;\n        } catch (Exception e) {\n            log.error(\"java task failed \", e);\n            setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE);\n            throw new TaskException(\"run java task error\", e);\n        }\n    }\n\n    /**\n     * Construct a shell command for the java -jar Run mode\n     *\n     * @return String\n     **/\n    protected String buildJarCommand() {\n        ResourceContext resourceContext = taskRequest.getResourceContext();\n        String mainJarAbsolutePathInLocal = resourceContext\n                .getResourceItem(javaParameters.getMainJar().getResourceName())\n                .getResourceAbsolutePathInLocal();\n        StringBuilder builder = new StringBuilder();\n        builder.append(getJavaCommandPath())\n                .append(Constants.SPACE)\n                .append(javaParameters.getJvmArgs().trim()).append(Constants.SPACE)\n                .append(buildResourcePath()).append(Constants.SPACE)","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-java/src/main/java/org/apache/dolphinscheduler/plugin/task/java/JavaTask.java#L107-L143","documentation":"JavaTask wraps any unexpected exception thrown while running the java task (either the java -jar or run-jar/class execution path) into a TaskException with the message 'run java task error'. It is the generic failure handler in JavaTask.handle(): when ShellCommandExecutor or the underlying java process fails with a non-InterruptedException, the exit status is set to failure and this exception propagates to the worker's task execution framework.","triggerScenarios":"JavaTask.handle() is invoked and the execution of the constructed shell command fails for any reason other than InterruptedException — e.g. ShellCommandExecutor.run throws, the java process exits abnormally, or any RuntimeException escapes the try block after the InterruptedException catch.","commonSituations":"Invalid java task parameters (main jar path wrong or resource not downloaded), java not found on the worker PATH, the jar throwing at runtime with a non-zero exit, JVM OOM, or filesystem permission problems when running the spawned java process.","solutions":["Inspect the full stack trace and the shell task logs in the worker log; the real cause is the wrapped exception 'e'.","Verify the mainJar resource exists on the worker and the resource center downloaded it correctly.","Confirm java is installed and on PATH on the worker, with a compatible version for the jar.","Fix the task's java program type / main class / JVM args in the task definition.","If the jar itself fails, run it manually on the worker with the same command (shown in task logs) to reproduce."],"exampleFix":"// before\n} catch (Exception e) {\n    throw new TaskException(\"run java task error\", e);\n}\n// after\n} catch (Exception e) {\n    log.error(\"java task failed with exitCode {}\", getExitStatusCode(), e);\n    setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE);\n    throw new TaskException(\"run java task error: \" + e.getMessage(), e);\n}","handlingStrategy":"try-catch","validationCode":"// preflight before scheduling the java task\nFile jar = new File(taskParams.getMainJar().getRes());\nif (!jar.isFile()) throw new IllegalStateException(\"main jar missing: \" + jar);\nif (Runtime.getRuntime().exec(new String[]{\"sh\",\"-c\",\"command -v java\"}).waitFor() != 0)\n    throw new IllegalStateException(\"java not on PATH\");","typeGuard":"static boolean isTaskException(Throwable t) {\n    return t instanceof TaskException;\n}","tryCatchPattern":"try {\n    javaTask.handle(callBack);\n} catch (TaskException e) {\n    log.error(\"java task failed, see cause for root reason\", e);\n    Throwable root = e.getCause();\n    if (root instanceof InterruptedException) {\n        Thread.currentThread().interrupt();\n    }\n}","preventionTips":["Validate the main jar resource exists and downloads correctly before execution.","Pin a compatible JDK on all worker images and keep it on PATH.","Run the jar manually with the exact logged command when triaging.","Keep JVM heap args within worker memory limits to avoid OOM kills."],"tags":["java-task","task-execution","wrapped-exception","dolphinscheduler"],"backgroundTag":"task-execution-failed","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}