RFR: 8346946: Allow class loaders to bind to layers for service loading

David M. Lloyd duke at openjdk.org
Thu Jan 2 17:21:10 UTC 2025


When loading services by class loader (`ServiceLoader.load(Class,ClassLoader)`), the module layers bound to the given class loader are searched for services, along with the layers bound to class loader's parent, and so on. For non-hierarchical class loader arrangements, this breaks down because the parent class loader of non-hierarchical class loaders is typically `null` (i.e. the boot class loader), while the class loader might have multiple dependency class loaders which replace the role of parent.

Add an API to `ClassLoader` which allows additional layers to be bound to the class loader for the purpose of service loading by class loader, without affecting reliable configuration of modules (see [JDK-8346439](https://bugs.openjdk.org/browse/JDK-8346439)), which allows non-hierarchical class loaders to resolve service providers in dependency class loaders.

-------------

Commit messages:
 - 8346946: Allow class loaders to bind to layers for service loading

Changes: https://git.openjdk.org/jdk/pull/22905/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=22905&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8346946
  Stats: 26 lines in 2 files changed: 15 ins; 0 del; 11 mod
  Patch: https://git.openjdk.org/jdk/pull/22905.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/22905/head:pull/22905

PR: https://git.openjdk.org/jdk/pull/22905


More information about the core-libs-dev mailing list