Skip to content

Commit

Permalink
UNSAFE.throwException null arg crashes JVM
Browse files Browse the repository at this point in the history
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 netty#4131
  • Loading branch information
Scottmitch committed Aug 27, 2015
1 parent 73f472b commit cbc38e9
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
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.*}.
*/
Expand Down Expand Up @@ -144,8 +146,9 @@ static boolean unalignedAccess() {
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) {
Expand Down

0 comments on commit cbc38e9

Please sign in to comment.