Skip to content

Commit

Permalink
8313874: JNI NewWeakGlobalRef throws exception for null arg
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes, kbarrett, shade
  • Loading branch information
olivergillespie authored and shipilev committed Aug 10, 2023
1 parent 83adaf5 commit 028b3ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hotspot/share/prims/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2875,7 +2875,7 @@ JNI_ENTRY(jweak, jni_NewWeakGlobalRef(JNIEnv *env, jobject ref))
HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY(env, ref);
Handle ref_handle(thread, JNIHandles::resolve(ref));
jweak ret = JNIHandles::make_weak_global(ref_handle, AllocFailStrategy::RETURN_NULL);
if (ret == nullptr) {
if (ret == nullptr && ref_handle.not_null()) {
THROW_OOP_(Universe::out_of_memory_error_c_heap(), nullptr);
}
HOTSPOT_JNI_NEWWEAKGLOBALREF_RETURN(ret);
Expand Down
10 changes: 10 additions & 0 deletions test/hotspot/jtreg/runtime/jni/ReturnJNIWeak/ReturnJNIWeak.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,19 @@ private static void testClear() throws Exception {
}
}

// Verify passing a null value returns null and doesn't throw.
private static void testNullValue() {
System.out.println("running testNullValue");
registerObject(null);
if (getObject() != null) {
throw new RuntimeException("expected null");
}
}

public static void main(String[] args) throws Exception {
testSanity();
testSurvival();
testClear();
testNullValue();
}
}

1 comment on commit 028b3ae

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.