Skip to content

fix(java/driver/jni): check for pending exceptions more thoroughly#4398

Draft
lidavidm wants to merge 1 commit into
apache:mainfrom
lidavidm:jni-exception-check
Draft

fix(java/driver/jni): check for pending exceptions more thoroughly#4398
lidavidm wants to merge 1 commit into
apache:mainfrom
lidavidm:jni-exception-check

Conversation

@lidavidm

Copy link
Copy Markdown
Member

After JNI calls that can leave a pending Java exception (GetArrayLength, GetObjectArrayElement, GetIntArrayRegion, GetByteArrayRegion, NewByteArray, SetByteArrayRegion) and are followed by further JNI or native ADBC work, check env->ExceptionCheck() and return the function's existing error default, letting the pending exception propagate to Java rather than performing more work or raising a second exception.

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

After JNI calls that can leave a pending Java exception (GetArrayLength,
GetObjectArrayElement, GetIntArrayRegion, GetByteArrayRegion, NewByteArray,
SetByteArrayRegion) and are followed by further JNI or native ADBC work,
check env->ExceptionCheck() and return the function's existing error
default, letting the pending exception propagate to Java rather than
performing more work or raising a second exception.

Generated-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 strengthens JNI error handling in the Java JNI driver by explicitly checking for pending Java exceptions after specific JNI calls, and returning early to let the original Java exception propagate instead of continuing native work (which could trigger additional failures or secondary exceptions).

Changes:

  • Added env->ExceptionCheck() short-circuit returns after array length and element access in openDatabase and metadata helpers.
  • Added exception checks around byte-array allocation and population (NewByteArray, SetByteArrayRegion) in *GetOptionBytes paths.
  • Added exception checks after reading array contents (GetArrayLength, Get*ArrayRegion) in *SetOptionBytes paths.

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

Comment on lines 339 to +340
const jsize num_params = env->GetArrayLength(parameters);
if (env->ExceptionCheck()) return nullptr;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This will conflict with other changes so let's wait for other PRs first

@lidavidm lidavidm marked this pull request as ready for review June 15, 2026 13:06
@lidavidm lidavidm marked this pull request as draft June 15, 2026 13:06
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.

2 participants