GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — NullPointerException in `PlatformDependent0.safeConstructPutInt` with Netty 4.2.2 and GraalVM Native Image on JDK25+ · Issue #15493 · netty/netty

NullPointerException in PlatformDependent0.safeConstructPutInt with Netty 4.2.2 and GraalVM Native Image on JDK25+ #15493

New issue
Copy link
New issue
Copy link
Closed
Closed
NullPointerException in PlatformDependent0.safeConstructPutInt with Netty 4.2.2 and GraalVM Native Image on JDK25+#15493
Copy link
Milestone
4.2.3.Final

Description

@patrick96
patrick96
opened on Jul 15, 2025
Issue body actions

Compiling an app running a netty server using Native Image results in a NullPointerException in PlatformDependent0 when the server receives any data.

  • Repo with exact reproducer: https://github.com/patrick96/netty-ni-bug
  • Requires netty 4.2.2
  • Requires a GraalVM early access build for JDK25 or higher. (I reproduced it with jdk-25.0.0-ea.26 and jdk-26.0.0-ea.03)
  • Only happens with native image, running in JVM mode works fine

Sample stack trace:

java.lang.NullPointerException
        at io.netty.util.internal.PlatformDependent0.safeConstructPutInt(PlatformDependent0.java:681)
        at io.netty.util.internal.PlatformDependent.safeConstructPutInt(PlatformDependent.java:569)
        at io.netty.util.internal.ReferenceCountUpdater.setInitialValue(ReferenceCountUpdater.java:67)
        at io.netty.buffer.AdaptivePoolingAllocator$Chunk.<init>(AdaptivePoolingAllocator.java:884)
        at io.netty.buffer.AdaptivePoolingAllocator$Magazine.newChunkAllocation(AdaptivePoolingAllocator.java:805)
        at io.netty.buffer.AdaptivePoolingAllocator$Magazine.allocate(AdaptivePoolingAllocator.java:703)
        at io.netty.buffer.AdaptivePoolingAllocator$Magazine.tryAllocate(AdaptivePoolingAllocator.java:574)
        at io.netty.buffer.AdaptivePoolingAllocator.allocate(AdaptivePoolingAllocator.java:230)
        at io.netty.buffer.AdaptivePoolingAllocator.allocate(AdaptivePoolingAllocator.java:217)
        at io.netty.buffer.AdaptiveByteBufAllocator.newDirectBuffer(AdaptiveByteBufAllocator.java:70)
        at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:188)
        at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:179)
        at io.netty.buffer.AbstractByteBufAllocator.ioBuffer(AbstractByteBufAllocator.java:140)
        at io.netty.channel.DefaultMaxMessagesRecvByteBufAllocator$MaxMessageHandle.allocate(DefaultMaxMessagesRecvByteBufAllocator.java:120)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
        at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.handle(AbstractNioChannel.java:445)
        at io.netty.channel.nio.NioIoHandler$DefaultNioRegistration.handle(NioIoHandler.java:381)
        at io.netty.channel.nio.NioIoHandler.processSelectedKey(NioIoHandler.java:575)
        at io.netty.channel.nio.NioIoHandler.processSelectedKeysPlain(NioIoHandler.java:520)
        at io.netty.channel.nio.NioIoHandler.processSelectedKeys(NioIoHandler.java:493)
        at io.netty.channel.nio.NioIoHandler.run(NioIoHandler.java:468)
        at io.netty.channel.SingleThreadIoEventLoop.runIo(SingleThreadIoEventLoop.java:206)
        at io.netty.channel.SingleThreadIoEventLoop.run(SingleThreadIoEventLoop.java:177)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:1073)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base@26/java.lang.Thread.runWith(Thread.java:1487)
        at java.base@26/java.lang.Thread.run(Thread.java:1474)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:832)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:808)

Since version 4.2 (#15231, #15338), Netty doesn't use Unsafe anymore for JDK25+. However, the NPE is thrown in the unsafe code because the Unsafe instance is null, which should be impossible.

I didn't manage to build netty from source to confirm this but my best guess is that this happens due to AdaptivePoolingAllocatorSubstitution:

  • ReferenceCountUpdater.setInitialValue checks unsafeOffset() to determine whether unsafe should be used (in this case it shouldn't be used, but the offset is still no -1)
  • unsafeOffset() in AdaptivePoolingAllocator$Chunk.updater returns AdaptivePoolingAllocator.Chunk.REFCNT_FIELD_OFFSET
  • This is usually computed using ReferenceCountUpdater.getUnsafeOffset, which would return -1 because unsafe is not available
  • However, on native image the AdaptivePoolingAllocatorSubstitution class recomputes the field value of REFCNT_FIELD_OFFSET to use the offset as provided by native image (which is never -1), effectively making the code think unsafe is available here

Activity

  1. fniephaus commented on Jul 15, 2025

    @fniephaus
    fniephaus
    on Jul 15, 2025
    More actions

    (Disclaimer: Patrick and I work on the GraalVM team)

    #14928 introduced a dependency on org.graalvm.nativeimage:svm to implement the AdaptivePoolingAllocatorSubstitution. This dependency is considered internal API and we highly discourage the use of substitutions as they can cause issues like this one.

    It would be good to find a way to make this work without the substitution.

  2. yawkat commented on Jul 15, 2025

    @yawkat
    yawkat
    on Jul 15, 2025
    Contributor
    More actions

    #15354

  3. patrick96 commented on Jul 15, 2025

    @patrick96
    patrick96
    on Jul 15, 2025
    Author
    More actions

    Oh wow, netty 4.2.3 came out 18 hours ago and I just didn't see it because it wasn't yet up on mvnrepository.

    I can confirm, this no longer happens with 4.2.3

    Reacted by Jonas Konrad, Fabio Niephaus and Chris Vest
  4. patrick96
    closed this as completedon Jul 15, 2025
  5. fniephaus commented on Jul 15, 2025

    @fniephaus
    fniephaus
    on Jul 15, 2025
    More actions

    Nice, thank you @yawkat. Do you think there is any way the substitution can be avoided altogether?

  6. yawkat commented on Jul 15, 2025

    @yawkat
    yawkat
    on Jul 15, 2025
    Contributor
    More actions

    It's needed for unsafe, which is faster than the modern alternatives, so I don't see how 🤷

  7. normanmaurer
    added this to the 4.2.3.Final milestone on Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • 4.2.3.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.