Although I doubt that making sure a library _only_ works on the module path is a good idea, would it make sense to introduce a helper method for this check? Something like:
Module.assertOnModulePath() ? 2018-03-28 9:41 GMT+02:00 Remi Forax <fo...@univ-mlv.fr>: > yes, > !Whatever.class.getModule().isNamed() > > Rémi > > ----- Mail original ----- > > De: "Peter Levart" <peter.lev...@gmail.com> > > À: "mark reinhold" <mark.reinh...@oracle.com>, "jigsaw-dev" < > jigsaw-dev@openjdk.java.net> > > Envoyé: Mercredi 28 Mars 2018 09:28:23 > > Objet: Re: The baby and the bathwater > > > On 03/26/18 20:08, mark.reinh...@oracle.com wrote: > >> Stephen closes with a specific suggestion: > >> > >> "There needs to be a way for a library author to insist that the > >> modular jar file they are producing can only be run on the > module-path > >> (with any attempt to use it on the class-path preventing application > >> startup). This would eliminate the need for testing both class-path > >> and module-path." > > > > That's easy to enforce in runtime. Just take a "victim" class from your > > library that is most often needed when your library is being used (or > > take a couple of them) and add a class initialization block like the > > following to them: > > > > public class Whatever { > > > > static { > > if (Whatever.class.getModule().getName() == null) { > > throw new Error("Can only use this library as a module"); > > } > > } > > > > > > Regards, Peter >