Bamboo Java Specs scanning in Docker fails with java.lang.NullPointerException

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Low
    • 8.1.2, 8.0.6, 8.2.0
    • Affects Version/s: 8.0.0, 8.0.0 EAP1, 8.0.1, 8.0.2
    • Component/s: Bamboo Specs
    • None
    • 2
    • Severity 3 - Minor

      Issue Summary

      When Bamboo scan for Bamboo Specs it tries to load the images in the local cache to find a matching tag given in the Bamboo-> Security-configuration.
      While it is scanning if it finds a null RepoTag it throws a java.lang.NullPointerException and gives an error in Repo Bamboo Spec Scanning.

      Steps to Reproduce

      Have a docker image with a null RepoTag. Build a container and tag it with the same Tag of an image you already have. You will notice that the "old" image will be untagged (<none>) and the new image will receive the latest tag.

      # docker pull pvnovarese/mprime
      Using default tag: latest
      latest: Pulling from pvnovarese/mprime
      Image docker.io/pvnovarese/mprime:latest uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/deprecated-schema-v1/
      a3ed95caeb02: Pull complete 
      546e579918ed: Pull complete 
      Digest: sha256:21561b776f6e3f30044d09e40f31d696425354e4a1885da10c153eb5bb707237
      Status: Downloaded newer image for pvnovarese/mprime:latest
      docker.io/pvnovarese/mprime:latest
      
      # docker build -t pvnovarese/mprime .
      Sending build context to Docker daemon  2.048kB
      Step 1/1 : FROM hello-world
       ---> feb5d9fea6a5
      Successfully built feb5d9fea6a5
      Successfully tagged pvnovarese/mprime:latest
      
      # docker images | grep pvnovarese
      pvnovarese/mprime                latest        feb5d9fea6a5   5 days ago      13.3kB
      pvnovarese/mprime                <none>        ba0e5ba59f5c   5 years ago     4.46MB 
      
      $ curl --unix-socket /var/run/docker.sock http://localhost/v1.41/images/json | jq
      ...
        {
          "Containers": -1,
          "Created": 1450483765,
          "Id": "sha256:ba0e5ba59f5cb2379ecc51ab9940fd6912d844699cefbcddd657df2b07e0fb69",
          "Labels": {},
          "ParentId": "",
          "RepoDigests": [
            "pvnovarese/mprime@sha256:21561b776f6e3f30044d09e40f31d696425354e4a1885da10c153eb5bb707237"
          ],
          "RepoTags": null,
          "SharedSize": -1,
          "Size": 4460952,
          "VirtualSize": 4460952
        }
      

      After that, run a Bamboo Spec Scan with docker on any Linked repository and observe the error.

      NOTICE: In an attempt to reproduce the error, the atlassian/bamboo-specs-runner:8.0.1 image was pulled from Docker registry and apparently fixed the issue. But after a few tentatives with the image already on the server, the error showed up again, meaning that anyMatch is capturing the broken RepoTag image randomly from the provided map list from docker.listImages() stream.

      Expected Results

      Bamboo should be able to initialise the bamboo-specs-runner container and scan the Specs without errors.

      Actual Results

      Throwing NullPointException while scanning the list of images and stop scanning the rest.

      RepositoryStoredSpecsExecutionServiceImpl

      private boolean isDockerImageInCache(@NotNull String dockerImage, DockerClient docker) throws DockerException, InterruptedException {
              return docker.listImages().stream()
                      .map(Image::repoTags)
                      .flatMap(List::stream)
                      .anyMatch(tag -> tag.equals(dockerImage));
          }
      

      The below exception is thrown in the file:

      java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.NullPointerException. Listener: com.atlassian.bamboo.plugins.stash.events.BranchChangedEventListener event: com.atlassian.stash.plugin.remote.event.StashBranchChangedRemoteEvent
      	at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:53)
      	at com.atlassian.event.internal.ComparableListenerInvoker.invoke(ComparableListenerInvoker.java:48)
      	at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.lambda$null$0(AsynchronousAbleEventDispatcher.java:37)
      	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      	at com.atlassian.bamboo.utils.BambooRunnables$1.run(BambooRunnables.java:48)
      	at com.atlassian.bamboo.security.ImpersonationHelper.runWith(ImpersonationHelper.java:26)
      	at com.atlassian.bamboo.security.ImpersonationHelper.runWithSystemAuthority(ImpersonationHelper.java:17)
      	at com.atlassian.bamboo.security.ImpersonationHelper$1.run(ImpersonationHelper.java:41)
      	at java.base/java.lang.Thread.run(Thread.java:829)
      Caused by: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.NullPointerException
      	at com.atlassian.bamboo.configuration.external.rss.RepositoryStoredSpecsExecutionServiceImpl.generateBambooYamlsFromSpecs(RepositoryStoredSpecsExecutionServiceImpl.java:145)
      	at com.atlassian.bamboo.configuration.external.rss.JavaSpecsImportServiceImpl.lambda$processSpecs$0(JavaSpecsImportServiceImpl.java:67)
      	at com.atlassian.bamboo.configuration.external.rss.SpecsOptimizeProcessor.processSpecs(SpecsOptimizeProcessor.java:37)
      	at com.atlassian.bamboo.configuration.external.rss.JavaSpecsImportServiceImpl.processSpecs(JavaSpecsImportServiceImpl.java:93)
      	at com.atlassian.bamboo.configuration.external.RepositoryStoredSpecsServiceImpl.runBambooSpecs(RepositoryStoredSpecsServiceImpl.java:204)
      	at com.atlassian.bamboo.configuration.external.RssDetectionServiceImpl.runRssDetection(RssDetectionServiceImpl.java:374)
      	at com.atlassian.bamboo.configuration.external.detection.RssDetectionRunnable.run(RssDetectionRunnable.java:42)
      	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
      	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      	... 7 more
      Caused by: java.util.concurrent.ExecutionException: java.lang.NullPointerException
      	at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
      	at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
      	at com.atlassian.bamboo.configuration.external.rss.RepositoryStoredSpecsExecutionServiceImpl.generateBambooYamlsFromSpecs(RepositoryStoredSpecsExecutionServiceImpl.java:137)
      	... 15 more
      Caused by: java.lang.NullPointerException
      	at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:271)
      	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
      	at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1632)
      	at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
      	at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
      	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
      	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
      	at java.base/java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:230)
      	at java.base/java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:196)
      	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
      	at java.base/java.util.stream.ReferencePipeline.anyMatch(ReferencePipeline.java:528)
      	at com.atlassian.bamboo.configuration.external.rss.RepositoryStoredSpecsExecutionServiceImpl.isDockerImageInCache(RepositoryStoredSpecsExecutionServiceImpl.java:305)
      	at com.atlassian.bamboo.configuration.external.rss.RepositoryStoredSpecsExecutionServiceImpl.updateDockerImageCache(RepositoryStoredSpecsExecutionServiceImpl.java:287)
      	at com.atlassian.bamboo.configuration.external.rss.RepositoryStoredSpecsExecutionServiceImpl.lambda$runSpecsWithDocker$1(RepositoryStoredSpecsExecutionServiceImpl.java:222)

      Workaround

      Workaround 1

      You could create a tag for those images and re-try the Bamboo Spec scanning. Alternatively, purge those untagged images if you are not using them.

      Workaround 2

      You can disable processing Bamboo Specs within Docker at Bamboo Administration >> Security Settings >> Process Bamboo Specs in Docker however please note, you would be disabling a security feature that is intended to provide some isolation from the Bamboo Server and the Specs that are being processed.

      Workaround 3

      Set the bamboo.repository.stored.specs.image.pull.force=true Bamboo system environment/property to always pull the image so Bamboo should pull Docker image to run Specs processing even if it exists at local Docker cache. This would slow down the Bamboo Spec scanning process:

            Assignee:
            Alexey Chystoprudov
            Reporter:
            Vani
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: