Skip to content

[Bug]: NullPointerException from ResourceReaper in GenericContainer.stop #11492

Open

Description

@findepi

Module

Core

Testcontainers version

2.0.3

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host Arch

x86

Docker version

GitHub hosted runners

What happened?

java.lang.NullPointerException: Cannot invoke "Object.hashCode()" because "key" is null
	at java.base/java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1125)
	at java.base/java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1116)
	at org.testcontainers.utility.ResourceReaper.stopAndRemoveContainer(ResourceReaper.java:175)
	at org.testcontainers.containers.GenericContainer.stop(GenericContainer.java:652)
	at io.trino.tests.product.launcher.env.DockerContainer.reset(DockerContainer.java:411)
	at io.trino.tests.product.launcher.env.Environment.tryStart(Environment.java:157)

Exact repro steps are unclear.
Based on exceptions logged earlier in the CI run (https://github.com/trinodb/trino/actions/runs/22016571723/job/63619535768?pr=28120) this may be after a failed startup attempt.

Relevant log output

Additional Information

https://github.com/trinodb/trino/actions/runs/22016571723/job/63619535768?pr=28120

Activity

  1. PreAgile commented on Mar 27, 2026

    @PreAgile
    Contributor

    I took a look at this — the NPE comes from ConcurrentHashMap.remove(null) inside stopAndRemoveContainer(), since ConcurrentHashMap doesn't accept null keys.

    One thing I noticed is that GenericContainer.stop() already guards against a null containerId before calling into ResourceReaper, so it's not obvious how null gets through. Could be a race or another caller hitting the deprecated overload.

    I'm thinking a simple null check (early return) in both stopAndRemoveContainer() overloads would prevent the crash. The deeper root cause could be investigated separately if needed.

    Would that approach work, or would you prefer finding the exact path first?

  2. radhika4229 commented on Aug 3, 2026

    @radhika4229

    "Hi, I'd like to work on this if it's still open. Could you share any pointers on reproducing this or which part of ResourceReaper is involved?"

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions