@@ -154,7 +154,6 @@ public void afterAnalysis(AfterAnalysisAccess access) {
154154 * is required when filtering the analysis reachable module set.
155155 */
156156 Set <String > extraModules = new HashSet <>();
157- List <String > nonExplicit = List .of ("ALL-DEFAULT" , "ALL-SYSTEM" , "ALL-MODULE-PATH" );
158157 String explicitlyAddedModules = System .getProperty (ModuleSupport .PROPERTY_IMAGE_EXPLICITLY_ADDED_MODULES , "" );
159158 if (!explicitlyAddedModules .isEmpty ()) {
160159 extraModules .addAll (Arrays .asList (SubstrateUtil .split (explicitlyAddedModules , "," )));
@@ -167,30 +166,44 @@ public void afterAnalysis(AfterAnalysisAccess access) {
167166 * modules as specified in the https://openjdk.org/jeps/261. See
168167 * {@link ModuleLayerFeature.typeIsModuleRootOrReachable(AnalysisType)} for more details.
169168 */
170- Stream <AnalysisType > rootModuleTypes ;
169+ Stream <Module > rootModules ;
170+ List <String > nonExplicit = List .of ("ALL-DEFAULT" , "ALL-SYSTEM" , "ALL-MODULE-PATH" );
171171 if (accessImpl .getApplicationClassPath ().isEmpty () && nonExplicit .stream ().noneMatch (extraModules ::contains )) {
172- rootModuleTypes = universe .getTypes ()
172+ rootModules = universe .getTypes ()
173173 .stream ()
174- .filter (ModuleLayerFeature ::typeIsReachable );
174+ .filter (ModuleLayerFeature ::typeIsReachable )
175+ .map (t -> t .getJavaClass ().getModule ());
175176 } else {
176- rootModuleTypes = universe .getTypes ()
177- .stream ()
178- .filter (ModuleLayerFeature ::typeIsModuleRootOrReachable );
179-
180- /*
181- * Also make sure to include modules not seen by the analysis.
182- */
183- Set <String > extraUndiscoveredModules = ModuleLayer .boot ().modules ()
177+ Optional <Module > javaSeModule = universe .getTypes ()
184178 .stream ()
185- .filter (ModuleLayerFeature ::isModuleRoot )
186- .map (Module ::getName )
187- .collect (Collectors .toSet ());
188- extraModules .addAll (extraUndiscoveredModules );
179+ .filter (ModuleLayerFeature ::typeIsReachable )
180+ .map (t -> t .getJavaClass ().getModule ())
181+ .filter (m -> m .isNamed () && m .getName ().equals ("java.se" ))
182+ .findFirst ();
183+ if (javaSeModule .isPresent ()) {
184+ /*
185+ * The java.se module is a root, if it exists.
186+ */
187+ rootModules = Stream .of (javaSeModule .get ());
188+ } else {
189+ rootModules = universe .getTypes ()
190+ .stream ()
191+ .filter (ModuleLayerFeature ::typeIsModuleRootOrReachable )
192+ .map (t -> t .getJavaClass ().getModule ());
193+
194+ /*
195+ * Also make sure to include modules not seen by the analysis.
196+ */
197+ Set <String > extraUndiscoveredModules = ModuleLayer .boot ().modules ()
198+ .stream ()
199+ .filter (ModuleLayerFeature ::isModuleRoot )
200+ .map (Module ::getName )
201+ .collect (Collectors .toSet ());
202+ extraModules .addAll (extraUndiscoveredModules );
203+ }
189204 }
190205
191- Stream <Module > runtimeImageModules = rootModuleTypes
192- .map (t -> t .getJavaClass ().getModule ())
193- .distinct ();
206+ Stream <Module > runtimeImageModules = rootModules .distinct ();
194207
195208 Set <Module > runtimeImageNamedModules = runtimeImageModules
196209 .filter (Module ::isNamed )
0 commit comments