Fix JniCallback null check to test the NewGlobalRef result - #15063
Open
Sanjays2402 wants to merge 1 commit into
Open
Fix JniCallback null check to test the NewGlobalRef result#15063Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14974.
JniCallback's constructor creates a global ref for the Java callback object, but the guard checksjcallback_objrather thanm_jcallback_obj. Callers always pass a non-null local ref, so the branch is dead and a failedNewGlobalRef(OOM, with an exception pending) slips through. The object ends up withm_jcallback_obj == nullptrwhile the derived constructor keeps running and the native factory still hands back a handle.While fixing that I hit a second problem on the same path.
m_jvmandm_jcallback_objare never initialized, so the earlyreturnwhenGetJavaVMfails leaves both indeterminate.~JniCallbackthen readsm_jcallback_objand can callDeleteGlobalRefon garbage, andgetJniEnvuses a junkm_jvmbefore that. So:m_jcallback_objinstead of the inputm_jvmis null, since there's nothing to releaseThe destructor guard is what makes the OOM case actually safe to unwind rather than just detected.
This base class backs the comparator, logger, event listener, table filter, WAL filter, trace writer, transaction notifier and write batch handler bridges, so it's a shared path.
Compiled
java/rocksjni/jnicallback.ccclean against JDK 20 on macOS arm64. The behaviour only changes under allocation failure, which I don't have a good way to exercise in the existing Java test suite, so I've left it as a straight correctness fix with no new test.As the issue notes, a base ctor can't stop the derived ctor body from running. Propagating construction failure out of the individual callback ctors and factory functions is the larger follow-up and isn't in this change.