Skip to content

Java SDK: Clearer error when a task class cannot be instantiated#69827

Open
FrankYang0529 wants to merge 1 commit into
apache:mainfrom
FrankYang0529:airflow-java-sdk-printStackTrace
Open

Java SDK: Clearer error when a task class cannot be instantiated#69827
FrankYang0529 wants to merge 1 commit into
apache:mainfrom
FrankYang0529:airflow-java-sdk-printStackTrace

Conversation

@FrankYang0529

@FrankYang0529 FrankYang0529 commented Jul 13, 2026

Copy link
Copy Markdown
Member

Why

  • A Task class without a public no-argument constructor or a non-static inner class fails with a generic Error executing task plus a raw reflection trace, which steering Dag authors toward debugging execute() logic that never ran.

How

  • Split instantiation from execution in TaskRunner.runTask: instantiation failures now log Cannot instantiate task class. A task class must be concrete and declare a public no-argument constructor with a taskClass field.
  • Removed the redundant e.printStackTrace(). The structured log record already carries the full trace.
  • Documented the constructor requirement in the interface-API section of java.rst.

Verification

  • ./gradlew :sdk:test --tests "org.apache.airflow.sdk.execution.TaskTest"
  • E2E_TEST_MODE=java_sdk uv run --project airflow-e2e-tests pytest "tests/airflow_e2e_tests/java_sdk_tests/test_java_sdk_dag.py::TestJavaSDKUninstantiableExample" -xvs

Was generative AI tooling used to co-author this PR?
  • Yes - Claude Code

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! LGTM overall.

Comment thread airflow-core/docs/authoring-and-scheduling/language-sdks/java.rst Outdated
Signed-off-by: PoAn Yang <payang@apache.org>
@FrankYang0529
FrankYang0529 force-pushed the airflow-java-sdk-printStackTrace branch from d282d3c to bd67a38 Compare July 25, 2026 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants