Skip to content

fix(java/driver/jni): delete JNI local references#4397

Merged
lidavidm merged 1 commit into
apache:mainfrom
lidavidm:jni-local-ref
Jun 21, 2026
Merged

fix(java/driver/jni): delete JNI local references#4397
lidavidm merged 1 commit into
apache:mainfrom
lidavidm:jni-local-ref

Conversation

@lidavidm

Copy link
Copy Markdown
Member

Assisted-by: Claude Opus 4.8 noreply@anthropic.com

Assisted-by: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses potential JNI local reference table overflows/leaks in the Java ADBC JNI driver by explicitly deleting JNI local references that can otherwise accumulate during long-running native calls or loops.

Changes:

  • Delete the jstring local reference in JniStringView’s destructor after releasing UTF chars.
  • In statementExecutePartitions, add a null/exception check after NewByteArray and delete the per-iteration jbyteArray local reference after passing it to Java.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lidavidm lidavidm requested a review from amoeba June 15, 2026 02:37
@lidavidm lidavidm marked this pull request as ready for review June 15, 2026 02:37
@lidavidm lidavidm requested a review from zeroshade June 19, 2026 03:47

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

is there any way to test this and verify?

@lidavidm

Copy link
Copy Markdown
Member Author

I believe HotSpot/OpenJDK is not affected by this.

https://bugs.openjdk.org/browse/JDK-8297106

In practice, in Hotspot, the actual functionality of EnsureLocalcapacity is a no-op: there is no inherent local ref capacity limit: we create them till we run out of memory. So the Xcheck:jni version of EnsureLocalCapacity is just a way to encourage people to write portable JNI code, in case it runs on a VM that does have a limit.

It appears neither is Android, after 8.0:

https://developer.android.com/ndk/guides/jni-tips

In Android versions prior to Android 8.0, the number of local references is capped at a version-specific limit. Beginning in Android 8.0, Android supports unlimited local references.

So we would need to test a JVM implementation that isn't derived from OpenJDK, that isn't Android; I believe this is very very few implementations.

I can't find any reference to a limit for GraalVM, either. At this point the only other implementation I can think of is CheerpJ, but I don't think we support that in principle in the first place, so...

@lidavidm lidavidm merged commit 0fa2b15 into apache:main Jun 21, 2026
19 of 21 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