JDK-8196182 : ServiceLoader.iterator().hasNext()/.next() may throw a LinkageError
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 6,9,10,11
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2018-01-25
  • Updated: 2022-01-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
Based on JDK-8130493.

When using a ServiceLoader to load unnamed module classes, and if loading of that class fails with a LinkageError, the LinkageError is thrown out of the ServiceLoader's Iterator's hasNext() method, which seems to be against the javadoc/specification:

(From the ServiceLoader's top level javadoc:)

{quote}
 * <p> When using the service loader's {@code iterator}, the {@link
 * Iterator#hasNext() hasNext} and {@link Iterator#next() next} methods will
 * fail with {@link ServiceConfigurationError} if an error occurs locating,
 * loading or instantiating a service provider. When processing the service
{quote}

A testcase is attached.

Comments
Easy to fix but it changes long standing behavior. The issue does not exist for cases where there is a linkage error involved a service provider in a named module, those cases are correctly wrapped with a SCE.
25-01-2018