JDK-4456679 : Update java.nio.channels.spi.SelectorProvider to use java.util.ServiceLoader
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2001-05-09
  • Updated: 2024-10-09
  • Resolved: 2017-07-20
Related Reports
Relates :  
Description
Another very minor yet related issue that is perhaps not worth its own bugid: if the sun.misc.Service-located provider class does is not actually assignable to the service type, then it looks like a ClassCastException will be thrown in SelectorProvider.loadProviderAsService-- but the spec quoted in the Description of this bug report says "if this process fails then an unspecified error is thrown", which (from JLS2e 11.2.1) a reader might reasonably interpret that to mean <code>Error</code>.  [Perhaps this would be best addressed in sun.misc.Service itself, which could verify that a provider is assignable to the service type before returning it (or throw ServiceConfigurationError).]
peter.c.jones@east 2001-03-29

Comments
SelectorProvider was changed to use java.util.ServiceLoader several releases ago so I think we can close this issue.
20-07-2017

EVALUATION The description of this bug is partly a comment on the deliberately-vague specification of the NIO selector-provider mechanism, which couldn't mention sun.misc.ServiceConfigurationError since that error is not part of the platform API. The root problem, however, is that the NIO selector-provider code can throw a ClassCastException even though it's not specified to do so. The new java.util.Service class (4640520) will instantiate each provider and then cast it to the service type; if that operation fails then the resulting ClassCastException will be wrapped in a java.util.ServiceConfigurationError. When the NIO provider code is updated to use the new java.util.Service class then it will automagically benefit from this check and this bug can be closed. I'm therefore changing this bug into a request for that code to be so updated. (At that time it might also be worth revising the NIO spec to be more precise and require a ServiceConfigurationError to be thrown, but that would need to be covered by a separate request.)
08-09-2005