[External] : Re: provides and requires static ... runtime error

Alan Bateman Alan.Bateman at oracle.com
Thu Apr 20 14:27:35 UTC 2023


On 20/04/2023 14:55, Josiah Noel wrote:
> :
> if we don't export the implementation class, then the 
> ServiceLoader becomes the only mechanism by which it can be 
> instantiated. In this case, if the user doesn't add the optional 
> interface dependency, it becomes impossible to accidentally load the 
> interface and get a ClassNotFoundException when using module Y's 
> non-SPI packages.
>
There could be code in the module that references the implementation 
class, in which case you might get NCDFE at runtime. Requires-static 
might be okay during initial migration of older code that is okay with 
dangling references and uses reflection guards. For reliability, it is 
usually better to use services to implement optionality.

-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jigsaw-dev/attachments/20230420/cf4ebfe4/attachment.htm>


More information about the jigsaw-dev mailing list