-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Improve check for multiple junit-platform.properties files #2207
Copy link
Copy link
Closed
Description
Overview
Today, the following warning is generated...
...and emitted even if the junit-platform.properties resource is only once physically present.
This false positive is due to using...
...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
Reactions are currently unavailable