On Sun, 11 Aug 2024 at 17:19, Alan Bateman <alan.bate...@oracle.com> wrote: > Package.getPackage is deprecated a long time, I don't think we've seen too > many complaints. Nowadays it's probably not too useful except to get to > package annotations (everything else in that API dates from JDK 1.2 and the > since removed extension mechanism). > > The set of package names for packages in the modules defined to the boot > loader can be obtained with code like this: > > ModuleLayer.boot() > .modules() > .stream() > .filter(m -> m.getClassLoader() == null) > .flatMap(m -> m.getPackages().stream()) > .collect(Collectors.toSet()); > > which I think is what you are looking for here.
That doesn't quite work as it returns String package names, not Package objects (I need the Package object to maintain compatibility). Sounds like Package.getPackages() is the only current workaround. FWIW I do think there is a case to review the deprecation text of Package.getPackage(String). thanks Stephen