UNSAFE.throwException null arg crashes JVM

Motivation:
It has been observed that passing a null argument to Unsafe.throwException can crash the JVM.

Modifications:
- PlatformUnsafe0.throwException should honor http://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.18 and throw a NPE

Result:
No risk of JVM crashing for null argument.
Fixes https://github.com/netty/netty/issues/4131
This commit is contained in:
Scott Mitchell 2015-08-24 16:37:02 -07:00
parent 73f472b65d
commit cbc38e938a

View File

@ -30,6 +30,8 @@ import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLongFieldUpdater; import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
/** /**
* The {@link PlatformDependent} operations which requires access to {@code sun.misc.*}. * The {@link PlatformDependent} operations which requires access to {@code sun.misc.*}.
*/ */
@ -144,8 +146,9 @@ final class PlatformDependent0 {
return UNALIGNED; return UNALIGNED;
} }
static void throwException(Throwable t) { static void throwException(Throwable cause) {
UNSAFE.throwException(t); // JVM has been observed to crash when passing a null argument. See https://github.com/netty/netty/issues/4131.
UNSAFE.throwException(checkNotNull(cause, "cause"));
} }
static void freeDirectBuffer(ByteBuffer buffer) { static void freeDirectBuffer(ByteBuffer buffer) {