ClassLoader.getResources() only returns locations in a patch when using the module path and --patch-module

Andy Wilkinson awilkinson at pivotal.io
Tue Jul 3 08:28:00 UTC 2018


I recently raised a JDK issue [1] which, when triaged, was closed as not an
issue. I think is incorrect and was advised by Dalibor Topic [2] to email
this list so here I am.

In a nutshell, it appears that when using the module path and
--patch-module, a call to ClassLoader.getResources() will only return
resources locations that are within the patch and ignores those that are in
the original module.

There's a Git repository [3] that should reproduce the problem when you run
with ./mvnw test using Java 9 or later. The problem appears when using
Maven as Surefire launches the test VM with the main classes on the module
path and the test classes patched into the module. As a result, tests are
able to load classes from both the module and the patch but getResources()
only returns locations within the patch. As far as I can tell, Surefire is
configuring the JVM correctly when it launches it so this appears to be a
bug in the JDK.

Thanks,
Andy

[1] https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8206162
[2] https://twitter.com/robilad/status/1013850133589610496
[3] https://github.com/wilkinsona/module-path-scanning
<https://twitter.com/robilad/status/1013850133589610496>


More information about the core-libs-dev mailing list