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::TestJavaSDKUninstantiableTask" -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 java-sdk/processor/src/test/kotlin/org/apache/airflow/sdk/BuilderTest.kt Outdated
Comment thread airflow-core/docs/authoring-and-scheduling/language-sdks/java.rst Outdated
@FrankYang0529
FrankYang0529 force-pushed the airflow-java-sdk-printStackTrace branch from d282d3c to bd67a38 Compare July 25, 2026 01:37

@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.

Sorry that I didn't notice the docs issue in the last review. LGTM after resolving this change.

Comment thread airflow-core/docs/authoring-and-scheduling/language-sdks/java.rst Outdated
@FrankYang0529
FrankYang0529 force-pushed the airflow-java-sdk-printStackTrace branch from f309a2f to 88e1bde Compare August 2, 2026 13:06
@FrankYang0529
FrankYang0529 force-pushed the airflow-java-sdk-printStackTrace branch 3 times, most recently from 3a4be51 to 3d06494 Compare August 15, 2026 01:29
@FrankYang0529
FrankYang0529 requested a review from uranusjr August 17, 2026 02:19

@uranusjr uranusjr 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.

Should be good after fixing a couple of nits.

@FrankYang0529
FrankYang0529 force-pushed the airflow-java-sdk-printStackTrace branch 5 times, most recently from a8d40b9 to b0c5ee3 Compare August 23, 2026 13:12

@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.

Here're the final nits caught by Codex that make sense to me before merge. Would appreciate to address them when you have a moment, thanks.

Comment thread java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/execution/Task.kt Outdated
Comment thread airflow-core/docs/authoring-and-scheduling/language-sdks/java.rst
Comment thread dev/breeze/src/airflow_breeze/utils/selective_checks.py
Comment thread java-sdk/processor/src/test/kotlin/org/apache/airflow/sdk/BuilderTest.kt Outdated
@jason810496 jason810496 added this to the Java SDK 1.0 GA milestone Aug 24, 2026
Signed-off-by: PoAn Yang <payang@apache.org>
@FrankYang0529
FrankYang0529 force-pushed the airflow-java-sdk-printStackTrace branch from b0c5ee3 to 15803ca Compare August 24, 2026 06:27
@FrankYang0529

Copy link
Copy Markdown
Member Author

@jason810496 Thanks for the review and suggestion! I address all comments.

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.

3 participants