Fix DockerDesktopClientProviderStrategy always being applicable#11832
Open
seonwooj0810 wants to merge 1 commit into
Open
Fix DockerDesktopClientProviderStrategy always being applicable#11832seonwooj0810 wants to merge 1 commit into
seonwooj0810 wants to merge 1 commit into
Conversation
The socketPath field uses Lombok's @Getter(lazy = true), which rewrites it into an AtomicReference that is never null. isApplicable() compared the raw field against null, so it always returned true on Linux/macOS even when Docker Desktop was not installed. The strategy was then selected and getTransportConfig() threw a NullPointerException because the lazily-resolved getSocketPath() returned null. Check the generated getSocketPath() accessor instead so the resolved socket path (or null when no Docker Desktop socket exists) is evaluated. Fixes testcontainers#11829 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11829
Problem
DockerDesktopClientProviderStrategy.isApplicable()returnstrueon Linux/macOS even when Docker Desktop is not installed, after whichgetTransportConfig()throws aNullPointerException.The cause is a Lombok pitfall. The
socketPathfield is declared with@Getter(lazy = true):Lombok rewrites a
lazyfield into anAtomicReferencethat holds the memoized value, so the field itself is nevernull.isApplicable()checked the raw field rather than the generated accessor:As a result the strategy is always considered applicable, and
getTransportConfig()then dereferencesgetSocketPath()(which resolves tonullwhen no~/.docker/desktop/docker.sockor~/.docker/run/docker.sockexists), producing the NPE reported in #11829.Fix
Use the Lombok-generated
getSocketPath()accessor — which resolves the lazy value to the actualPath(ornull) — instead of reading the backing field directly.getDescription()andgetTransportConfig()already use the accessor; this alignsisApplicable()with them.Tests
Added
DockerDesktopClientProviderStrategyTest(no Docker required) covering both directions by pointinguser.homeat a temp directory:notApplicableWhenDockerDesktopSocketIsMissing— no Docker Desktop socket present ⇒isApplicable()isfalse. This fails on the current code (returnstrue) and passes with the fix.applicableWhenDockerDesktopSocketExists— a.docker/desktop/docker.sockpresent ⇒isApplicable()istrue.Verification done: ran
./gradlew :testcontainers:test --tests "org.testcontainers.dockerclient.DockerDesktopClientProviderStrategyTest"— both tests pass with the fix; reverting the one-line change makesnotApplicableWhenDockerDesktopSocketIsMissingfail, confirming the test reproduces the bug../gradlew spotlessApplyreports no formatting changes.