On Tue, 25 Aug 2026 09:09:31 GMT, Tushar saini <[email protected]> wrote:
> ## Summary
> - Return an empty `ServiceLoader` when the service type is an array class
> (e.g. `Object[].class`)
> - Fixes misleading `ServiceConfigurationError` ("service type not accessible
> to unnamed module") for invalid service types
> - Array classes can never have registered service providers, so an empty
> loader is the correct result
> - Matches behavior observed on Eclipse OpenJ9 (see JDK-8379812)
>
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK
> Interim AI Policy](https://openjdk.org/legal/ai).
>
> ## Problem
> `ServiceLoader.loadInstalled()` with an array service type (e.g. from
> `MethodType.genericMethodType(1, true).parameterType(1)`) throws
> `ServiceConfigurationError` because module access checks in `checkCaller()`
> fail for array types.
>
> ## Solution
> - Detect array service types via `Class.isArray()` before `checkCaller()`
> - Return a dedicated empty `ServiceLoader` whose iterator/stream yield no
> providers
> - Apply to all public `load*` entry points
>
> ## Test plan
> - [x] Added `test/jdk/java/util/ServiceLoader/ArrayServiceTypeTest.java`
> - [ ] `make run-test
> TEST=jdk/java/util/ServiceLoader/ArrayServiceTypeTest.java`
> - [ ] `make run-test TEST=jdk/java/util/ServiceLoader` (regression)
> - [ ] Manual repro from JDK-8379812 (`temp.java`) completes without exception
Please see my comment in the JBS issue from March, it is still TBD if this
should be specified as IAE as it is nonsensical to invoke ServiceLoader with an
array class.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/32515#issuecomment-5514794645