Skip to content

fix: align JNI Arrow C Data ownership#10

Merged
JingsongLi merged 1 commit into
apache:mainfrom
QuakeWang:fix/jni-arrow-ownership
May 20, 2026
Merged

fix: align JNI Arrow C Data ownership#10
JingsongLi merged 1 commit into
apache:mainfrom
QuakeWang:fix/jni-arrow-ownership

Conversation

@QuakeWang
Copy link
Copy Markdown
Contributor

Problem

The Java/JNI writer used inconsistent Arrow C Data ownership semantics.

In the writer open path, Java exported an ArrowSchema and released it only after native open returned successfully, while JNI only borrowed the schema. If native open failed, the exported C Data resources could be left unreleased.

The write path had the same issue for exported ArrowArray and ArrowSchema: JNI moved the structs but only cleared the Java-side structs after a successful import, so import failures could leave exported resources owned by Java without being released. This differed from the C FFI path, which clears the source structs immediately after taking ownership.

Closed writer paths in Java/Python also exported Arrow C Data before native rejected the write.

Fix

  • Make JNI writer open/write paths consume Arrow C Data structs with from_raw, clearing the caller structs immediately.
  • Release Java Arrow C exports in finally only when the struct still has an active release callback.
  • Check Java/Python closed writer state before exporting Arrow C Data.
  • Add Java/Python regression coverage for write-after-close.

@JingsongLi
Copy link
Copy Markdown
Contributor

@QuakeWang Thanks for your contribution, can you rebase the main?

Signed-off-by: QuakeWang <wangfuzheng0814@foxmail.com>
@QuakeWang QuakeWang force-pushed the fix/jni-arrow-ownership branch from 7448381 to 5d5075b Compare May 20, 2026 04:54
@QuakeWang
Copy link
Copy Markdown
Contributor Author

@QuakeWang Thanks for your contribution, can you rebase the main?

@JingsongLi Done :)

Copy link
Copy Markdown

@leaves12138 leaves12138 left a comment

Choose a reason for hiding this comment

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

Looks good to me. The JNI side now correctly moves ownership of Arrow C Data using from_raw, while Java releases only when the exported structs are still owned on the caller side. The added closed-writer checks also avoid exporting after close. I verified the targeted Java/JNI and Python paths locally.

@JingsongLi
Copy link
Copy Markdown
Contributor

+1

@JingsongLi JingsongLi merged commit dba937b into apache:main May 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants