-
Bug
-
Resolution: Fixed
-
P4
-
17, 21, 22
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8315229 | 21.0.1 | Oli Gillespie | P4 | Resolved | Fixed | b09 |
JDK-8317445 | 17.0.10-oracle | Calvin Cheung | P4 | Resolved | Fixed | b02 |
JDK-8315235 | 17.0.9 | Oli Gillespie | P4 | Resolved | Fixed | b05 |
> Returns NULL if obj refers to null, or if obj was a weak global reference, or if the VM runs out of memory. If the VM runs out of memory, an OutOfMemoryError will be thrown.
The current behaviour is that `NewWeakGlobalRef(nullptr)` throws an OutOfMemoryError, which it should not.
```
#include <stdio.h>
#include <jni.h>
#include "TestNull.h"
JNIEXPORT void JNICALL Java_TestNull_testNull(JNIEnv *env, jclass a) {
env->NewWeakGlobalRef(nullptr);
env->ExceptionDescribe();
}
```
```
class TestNull {
static { System.loadLibrary("testNull"); }
public static void main(String[] args) {
testNull();
}
public static native void testNull();
}
```
```
java -Djava.library.path=. TestNull
Exception in thread "main" java.lang.OutOfMemoryError: C heap space
at TestNull.testNull(Native Method)
at TestNull.main(TestNull.java:4)
```
It seems that [this code](https://github.com/openjdk/jdk/blob/dc01604756c22889412f9f25b534488180327317/src/hotspot/share/prims/jni.cpp#L2879-L2881) forgets to handle the case where the original argument was null.
Thanks to Boris Rasin for reporting this issue in https://github.com/corretto/corretto-17/issues/145.
- backported by
-
JDK-8315229 JNI NewWeakGlobalRef throws exception for null arg
- Resolved
-
JDK-8315235 JNI NewWeakGlobalRef throws exception for null arg
- Resolved
-
JDK-8317445 JNI NewWeakGlobalRef throws exception for null arg
- Resolved
- relates to
-
JDK-8194309 JNI handle allocation failure not reported correctly
- Resolved
- links to
-
Commit openjdk/jdk17u-dev/c91fb3f7
-
Commit openjdk/jdk21u/42aec914
-
Commit openjdk/jdk/028b3ae1
-
Review openjdk/jdk17u-dev/1688
-
Review openjdk/jdk21u/88
-
Review openjdk/jdk/15188