Skip to content

Improve check for multiple junit-platform.properties files #2207

@sormuras

Description

@sormuras

Overview

Today, the following warning is generated...

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

...and emitted even if the junit-platform.properties resource is only once physically present.

This false positive is due to using...

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

...which may include duplicated elements when a custom class loader hierarchy is used. For details see the "Implementation Requirements" at: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ClassLoader.html#getResources(java.lang.String)

Example

JDK 11, IntelliJ IDEA, in-module (white box) testing with...

  @Test
  void getJUnitPlatformProperties() throws Exception {
    var loader = getClass().getClassLoader();
    System.out.println("loader = " + loader);
    System.out.println("loader.parent = " + loader.getParent());
    System.out.println("loader.parent.parent = " + loader.getParent().getParent());
    System.out.println();
    System.out.println("single: " + loader.getResource("junit-platform.properties"));
    System.out.println();
    var urls = Collections.list(loader.getResources("junit-platform.properties"));
    urls.forEach(url -> System.out.println("multi: " + url));
    System.out.println();
    var distinct = new HashSet<>(urls);
    distinct.forEach(url -> System.out.println("distinct: " + url));
  }

...emits:

loader = jdk.internal.loader.ClassLoaders$AppClassLoader@28864e92
loader.parent = jdk.internal.loader.ClassLoaders$PlatformClassLoader@e24ddd0
loader.parent.parent = null

single: file:/.../.idea/out/test/de.sormuras.bach/junit-platform.properties

multi: file:/.../.idea/out/test/de.sormuras.bach/junit-platform.properties
multi: file:/.../.idea/out/test/de.sormuras.bach/junit-platform.properties

distinct: file:/.../.idea/out/test/de.sormuras.bach/junit-platform.properties

Deliverables

  • Prune duplicate elements before checking the amount of found resources

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions