Skip to content
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

cachePath and resolutionCachePath mkdir too early if the manager is being configured through code #696

Closed
demus-nine opened this issue Sep 8, 2021 · 2 comments

Comments

@demus-nine
Copy link

In commit c42a2c4 an effort is made to create a cache folder if it doesn't exists. I assume this works when the folder is configured using the properties file, but when trying to configure using code, mkdir is called when instantiating CacheHandler, which is called by the WebDriverManager constructor using a default new Config() instance. Thus you can't set any values on config, before the CacheHandler constructor is called.

    protected WebDriverManager() {
        config = new Config();
        cacheHandler = new CacheHandler(config);
        httpClient = new HttpClient(config);
        downloader = new Downloader(httpClient, config, this::postDownload);
        resolutionCache = new ResolutionCache(config);
        dockerService = new DockerService(config, httpClient, resolutionCache);
        versionDetector = new VersionDetector(config, httpClient);
        webDriverList = new CopyOnWriteArrayList<>();
        webDriverCreator = new WebDriverCreator(config);
    }

calls

    public CacheHandler(Config config) {
        this.config = config;

        File cacheFolder = new File(config.getCachePath());
        if (!cacheFolder.exists()) {
            cacheFolder.mkdirs();
        }
    }

At this point cacheFolder can only have its default value.
If you then change config.cacheFolder, webdrivermanager crashes when trying to resolve the non-existent other cache folder, because it is only attempted to be created once, in the constructor.
The mkdir should probably be moved to getCacheFolder.

@bonigarcia
Copy link
Owner

I invite you to create a PR to enhance this.

@bonigarcia
Copy link
Owner

I have just committed a patch to improve this. It will be available in next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants