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: phh
Backport-of: 028b3ae1b162bd8f7c340bfa6e9487ca83697955
  • Loading branch information
olivergillespie authored and Paul Hohensee committed Aug 29, 2023
1 parent 7ea65a0 commit c91fb3f
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 @@ -2918,7 +2918,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 == NULL) {
if (ret == NULL && ref_handle.not_null()) {
THROW_OOP_(Universe::out_of_memory_error_c_heap(), NULL);
}
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 c91fb3f

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