Why getting ExceptionInInitializerError using orElseThrow

I am writing microservices which will be dockerized and deployed on AWS. Part of the Integration test is to run Docker Compose on this Yaml file to start Docker container and run Docker images locally.

When I run the integration test with Maven, I am getting ExceptionInInitializerError. After some debugging, I realized that it existed before running docker-compose on the yaml file. The stack trace further indicate this is related to the path

  • Running tests with Docker and Jenkins - Test Result
  • getting python and react component based container to work
  • Docker cloud repository push: access to the requested resource is not authorized on Fedora 23
  • how to cache build env in docker-compose
  • Docker out of space when running bundle install
  • Access binaries inside docker
  • java.lang.ExceptionInInitializerError: null
            at com.palantir.docker.compose.execution.DockerComposeExecutable.lambda$dockerComposePath$8(DockerComposeExecutable.java:52)
            at java.util.Optional.orElseThrow(Optional.java:290)
            at com.palantir.docker.compose.execution.DockerComposeExecutable.dockerComposePath(DockerComposeExecutable.java:52)
    

    The exception is thrown at line 52 where orElseThrow is at inside the function below:

    @Value.Derived
    protected String dockerComposePath() {
        String pathToUse = DOCKER_COMPOSE_LOCATIONS.preferredLocation()
                .orElseThrow(() -> new IllegalStateException(
                        "Could not find docker-compose, looked in: " + DOCKER_COMPOSE_LOCATIONS));
    
        log.debug("Using docker-compose found at " + pathToUse);
    
        return pathToUse;
    }
    

    The constant DOCKER_COMPOSE_LOCSATIONS is defined in earlier section of the same class

     private static final DockerCommandLocations DOCKER_COMPOSE_LOCATIONS = new DockerCommandLocations(
                System.getenv("DOCKER_COMPOSE_LOCATION"),
                "/usr/local/bin/docker-compose",
                "/usr/bin/docker-compose"
        );
    

    The method preferredLocation basically verifies the paths of docker-compose

    public Optional<String> preferredLocation() {
            return possiblePaths.stream()
                    .filter(IS_NOT_NULL)
                    .filter(FILE_EXISTS)
                    .findFirst();
        }
    

    Since I am on a PC on which docker-compose is installed at /c/Program Files/Docker Toolbox/docker-compose, these Linux style paths /usr/.... are not valid. However, I did not have DOCKER_COMPOSE_LOCATION pointing to the right path in my environment. So this might be what is causing ExceptionInInitializerError. What I don’t understand is if the path is not defined, it should have thrown IllegalStateException according to the orElseThrow and printed out the message Could not find docker-compose, looked in. Why does it throw error ExceptionInInitializerError?

    PS even if I set the DOCKER_COMPOSE_LOCATION with the right path in my environment, it is still throwing the same error.

  • Multi Maven Module Spring MVC Project to Spring Boot
  • How to scp a folder from windows to boot2docker?
  • How to run shell script on host from docker container?
  • When, where and how does Visual Studio 2017 set the DOCKER_BUILD_SOURCE environment variable
  • How can I make actual image files persistent in file upload process running with docker?
  • Sharing POSTGRES's local DATA folder with DOCKER machine
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.