On Tue, 25 Aug 2026 09:09:31 GMT, Tushar saini <[email protected]> wrote:

> ### Summary
> - Reject invalid service types (primitive, array, and hidden classes) in 
> `ServiceLoader.load*` methods
> - Throw `IllegalArgumentException` with a clear `"not a valid service type"` 
> message
> - Fixes misleading `ServiceConfigurationError` (`service type not accessible 
> to unnamed module`) when an array class is passed
> - Aligns with review feedback on JDK-8379812 — throw instead of returning an 
> empty loader
> 
> - [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 `checkCaller()` fails module access 
> checks for array types — even though the real issue is an invalid service 
> type.
> ---
> ### Solution
> - Add `checkServiceType()` before `checkCaller()`
> - Reject primitive, array, and hidden classes
> - Throw `IllegalArgumentException`: `<type>: not a valid service type`
> - Apply to all public `load*` entry points
> - Update `ArrayServiceTypeTest` to expect `IllegalArgumentException`
> ---
> ### Testing
> - [x] `make run-test 
> TEST=jdk/java/util/ServiceLoader/ArrayServiceTypeTest.java`
> - [] `make run-test TEST=jdk/java/util/ServiceLoader`

This pull request has been closed without being integrated.

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

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

Reply via email to