## 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

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

Commit messages:
 - 8379812: ServiceLoader should handle array service types gracefully

Changes: https://git.openjdk.org/jdk/pull/32515/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=32515&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8379812
  Stats: 103 lines in 2 files changed: 103 ins; 0 del; 0 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

Reply via email to