Skip to content

Don't cache URL when loading junit-platform.properties contents #2194

@sormuras

Description

@sormuras

Today, the code in the launcher uses the convenient input stream accessor openStream() provided by the URL class:

https://github.com/junit-team/junit5/blob/efdb9fde6ca9fbc8b6795d5438c604aadd802e57/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/LauncherConfigurationParameters.java#L66-L68

This implicitly caches an underlying JAR file for the current VM, if the junit-platform.properties file is located in a JAR file. On Windows, that means a lock is held by the VM until its associated reference is garbage collected.

When, for example, testing the launcher framework within a test method that prepares a custom class-path or module-path with generated JAR files in a temporary directory, that temporary directory can't be deleted on Windows, due the lock of the cached JAR file reference.

Deliverables

  • Use the following code to prevent caching of an underlying JAR file:
URLConnection urlConnection = configFileUrl.openConnection();
urlConnection.setUseCaches(false);
try (InputStream inputStream = urlConnection.getInputStream()) {
 props.load(inputStream);
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions