-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing check for null causes NullPointerException in PullImageResultCallback.checkForDockerSwarmResponse #1998
Comments
Hi @TheHaf, since you mentioned this issue in the Podman issue I was wondering, where you able to replicate this using Docker as well? |
I don't have docker installed on my work machine due to company policy, but I was able to test the behavior on our CI platform where docker is still available. 😸
I don't know what triggers this call of So concerning the handling of auth problems, podman seems to behave differnet from Docker. I would see that as a separate issue though (and maybe on the side of podman once we know what triggers the different code path), as the kernel of this issue here is that the contract of a method (using |
I have the same error as well Caused by: java.lang.NullPointerException: Cannot invoke "String.matches(String)" because the return value of "com.github.dockerjava.api.model.PullResponseItem.getStatus()" is null |
@AshwinPrabhuB Can you please share if you are using Docker, or an alternative container solution? |
This is observed only when using podman and if the local does not have the image. If I pull the image myself through podman pull command-line, the test container can run with the local copy. I am using Default pull policy, hence it does not bother downloading the remote image and the issue is avoided. This is a good enough workaround for personal workstations, but cannot guarantee the VMs used in CI pipelines will always carry the image locally. I have not seen this problem with Docker and Rancher. This is Podman specific confirmed. I landed here from a reference in test-containers issue: testcontainers/testcontainers-java#2088 |
A good workaround for this issue for those using podman is to prefetch the image to local before test-containers bootstrap. This bug does not manifest if the image is available locally and default pull policy. If you are using maven to orchestrate your test routines in CI pipeline, a good workaround is to use the maven exec plugin and perform a docker pull of the image from the remote in the "generate-test-resources" phase. This ensures that when the test-containers code executes in the "test" phase, the image is already available locally and this bug is worked around. Ex:
and in pull.sh, pull the image, say Redis like so:
To make this complete, you will also require to set up 2 environment variables DOCKER_HOST and TESTCONTAINERS_RYUK_DISABLED (this is Podman specific). The latter is needed to suppress Ryuk as it is currently not supported in Podman. You would have to stop the container after the test run through test code (shutdown hooks if using Java)
The above works for maven setups, you may translate this solution to suit your build systems until this bug is fixed. |
@AshwinPrabhuB Pulling the images beforehand is a good workaround, so thumbs up. In our setup we are now caching all container images in a Nexus registry, so we set the environment variable Back to the issue at hand, I tried to take a look at the official Docker API but I couldn't find anything about this |
@TheHaf I did the same and also could not find it in the reference documentation. Sometimes with Docker, you can only find this information in their source code. |
Hi. I ran into the same error, and I am also using podman with its docker socket. It seems if there is any error (auth required but failed / manifest not found in the registry) the
|
The method
checkForDockerSwarmResponse
in the classPullImageResultCallback
contains a call toitem.getStatus()
(where item is of type PullResponseItem) and immediately calls.matches(...)
on the return value. However the methodgetStatus()
is defined in the class with an annotation@CheckForNull
indicating that the return value could be null. Because of that SonarLint marks the call as unsafe (rule java:S2259 - "Null pointers should not be dereferenced") and I was also able to trigger a NullPointerException:I was able to trigger the NullPointerException using the TestContainers library to try to pull an image from a remote repository that needs authentication without being logged in to said repository.
My suggestion would be to change the first line in the method
checkForDockerSwarmResponse
to the following:I can open a pull request for that change if that's ok.
The text was updated successfully, but these errors were encountered: