> ## 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
Tushar saini has updated the pull request incrementally with one additional
commit since the last revision:
8379812: Reject invalid service types in ServiceLoader
Throw IllegalArgumentException when the service type is a primitive type,
array class, or hidden class, instead of failing later with a misleading
ServiceConfigurationError about module accessibility.
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/32515/files
- new: https://git.openjdk.org/jdk/pull/32515/files/e0056cc8..9fb59d8e
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=32515&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=32515&range=00-01
Stats: 72 lines in 2 files changed: 19 ins; 32 del; 21 mod
Patch: https://git.openjdk.org/jdk/pull/32515.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/32515/head:pull/32515
PR: https://git.openjdk.org/jdk/pull/32515