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 351d4947dc..ea2bb9068f 100644 --- a/common/src/main/java/io/netty/util/internal/PlatformDependent0.java +++ b/common/src/main/java/io/netty/util/internal/PlatformDependent0.java @@ -167,6 +167,16 @@ final class PlatformDependent0 { unsafe = null; } } + + if (unsafe != null) { + // There are assumptions made where ever BYTE_ARRAY_BASE_OFFSET is used (equals, hashCodeAscii, and + // primitive accessors) that arrayIndexScale == 1, and results are undefined if this is not the case. + long byteArrayIndexScale = unsafe.arrayIndexScale(byte[].class); + if (byteArrayIndexScale != 1) { + logger.debug("unsafe.arrayIndexScale is {} (expected: 1). Not using unsafe.", byteArrayIndexScale); + unsafe = null; + } + } } UNSAFE = unsafe;