From 695c0806135380a524fe6a5323ed0b58ed53b5bd Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Mon, 24 Aug 2015 16:37:02 -0700 Subject: [PATCH] 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 --- .../java/io/netty/util/internal/PlatformDependent0.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/io/netty/util/internal/PlatformDependent0.java b/common/src/main/java/io/netty/util/internal/PlatformDependent0.java index e4670e9d28..3cd47b25af 100644 --- a/common/src/main/java/io/netty/util/internal/PlatformDependent0.java +++ b/common/src/main/java/io/netty/util/internal/PlatformDependent0.java @@ -30,6 +30,8 @@ import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicLongFieldUpdater; 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.*}. */ @@ -144,8 +146,9 @@ final class PlatformDependent0 { return UNALIGNED; } - static void throwException(Throwable t) { - UNSAFE.throwException(t); + static void throwException(Throwable cause) { + // 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) {