Skip to content

Fix Java SDK numeric XCom casting and remove unused XCom key field#68983

Merged
jason810496 merged 4 commits into
apache:mainfrom
FrankYang0529:airflow-jdk-int-cast-and-xcom-key
Jul 2, 2026
Merged

Fix Java SDK numeric XCom casting and remove unused XCom key field#68983
jason810496 merged 4 commits into
apache:mainfrom
FrankYang0529:airflow-jdk-int-cast-and-xcom-key

Conversation

@FrankYang0529

@FrankYang0529 FrankYang0529 commented Jun 25, 2026

Copy link
Copy Markdown
Member

1. Fix numeric XCom casting

Widen numeric XCom values through Number instead of casting the boxed value to the declared type:

  • primitive targets: ((Number) client.getXCom(...)).intValue()
  • boxed targets: Optional.ofNullable((Number) client.getXCom(...)).map(Number::intValue).orElse(null), so an absent XCom stays null rather than throwing.

2. Remove the unused key field from Builder.XCom

@Builder.XCom exposed a key field, but the annotation processor only reads task when generating the getXCom call, so key never affected the generated code.


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

  • 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 catch! LGTM overall.

Comment thread java-sdk/processor/src/main/kotlin/org/apache/airflow/sdk/BuilderProcessor.kt Outdated
@uranusjr

Copy link
Copy Markdown
Member

Hmm, I wonder if we should do this since Python’s Taskflow API does not support using an argument to pull from a custom key; it only supports the return value. Maybe we should remove key from Builder.XCom instead?

@FrankYang0529
FrankYang0529 force-pushed the airflow-jdk-int-cast-and-xcom-key branch from 5df4f1f to a55d99f Compare June 27, 2026 01:50
@FrankYang0529 FrankYang0529 changed the title Fix Java SDK @Builder.XCom dropping custom key and miscasting numbers Fix Java SDK numeric XCom casting Jun 27, 2026
@FrankYang0529
FrankYang0529 force-pushed the airflow-jdk-int-cast-and-xcom-key branch from a55d99f to b9b4f37 Compare June 27, 2026 06:59
@FrankYang0529 FrankYang0529 changed the title Fix Java SDK numeric XCom casting Fix Java SDK numeric XCom casting and remove unused XCom key field Jun 27, 2026
@FrankYang0529

Copy link
Copy Markdown
Member Author

Hmm, I wonder if we should do this since Python’s Taskflow API does not support using an argument to pull from a custom key; it only supports the return value. Maybe we should remove key from Builder.XCom instead?

Agreed, remove key from Builder.XCom. If user would like to pull a custom key, they still can do it via client.getXCom(key=..., taskId=...).

@FrankYang0529
FrankYang0529 marked this pull request as ready for review June 27, 2026 08:27
Comment thread java-sdk/example/src/java/org/apache/airflow/example/XComCastingExample.java Outdated
Comment thread java-sdk/processor/src/main/kotlin/org/apache/airflow/sdk/BuilderProcessor.kt Outdated
Comment thread java-sdk/processor/src/main/kotlin/org/apache/airflow/sdk/BuilderProcessor.kt Outdated
@FrankYang0529
FrankYang0529 force-pushed the airflow-jdk-int-cast-and-xcom-key branch from b9b4f37 to a95f544 Compare June 29, 2026 07:44

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

I just realized, we probably should mention in docs if you set up Builder.XCom to read into a primitive, but fail to actually push it, the cast would fail with a NullPointerException since there’s no way to represent a null in primitives. (By contrast, if you use e.g. Integer, you’d “safely” get null.)

We might want to add a case to emit a cleaner exception instead. This should be done in a separate PR.

@FrankYang0529

Copy link
Copy Markdown
Member Author

We might want to add a case to emit a cleaner exception instead. This should be done in a separate PR.

I will do it in the next PR. Thank you.

Generate accessors that widen through Number instead: primitive params use
((Number) x).intValue(), and boxed params use Optional.ofNullable(...).orElse(null)
so an absent XCom stays null. Add a java_xcom_casting_example DAG and processor
tests covering int->long->double widening and an absent boxed value.

Signed-off-by: PoAn Yang <payang@apache.org>
Signed-off-by: PoAn Yang <payang@apache.org>
Signed-off-by: PoAn Yang <payang@apache.org>
Signed-off-by: PoAn Yang <payang@apache.org>
@FrankYang0529
FrankYang0529 force-pushed the airflow-jdk-int-cast-and-xcom-key branch from a95f544 to 2af0c39 Compare July 1, 2026 10:49

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

@jason810496
jason810496 merged commit fa9e5c7 into apache:main Jul 2, 2026
86 checks passed
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