@@ -1530,7 +1530,19 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
15301530 List <Path > substitutedImageModulePath = imagemp .stream ().map (substituteModulePath ).toList ();
15311531
15321532 List <String > mainClassArg = config .getGeneratorMainClass ();
1533- Map <String , Path > modules = listModulesFromPath (javaExecutable , javaArgs , mainClassArg , mp .stream ().distinct ().toList (), imagemp .stream ().distinct ().toList ());
1533+ /*
1534+ * We are using the image generator for --list-modules. That cannot handle the same modules
1535+ * on the module path (--module-path) and image module path (-imagemp). Only pass modules
1536+ * via the image module path if it isn't already on the module path. Note that the path to
1537+ * the individual jars might be different between module path and image module path, so we
1538+ * use the file name for filtering.
1539+ */
1540+ Set <Path > imagempForListMods = imagemp .stream ().filter (Predicate .not (a -> {
1541+ return mp .stream ().anyMatch (b -> {
1542+ return a .getFileName ().equals (b .getFileName ());
1543+ });
1544+ })).collect (Collectors .toSet ());
1545+ Map <String , Path > modules = listModulesFromPath (javaExecutable , javaArgs , mainClassArg , mp .stream ().distinct ().toList (), imagempForListMods .stream ().distinct ().toList ());
15341546 if (!addModules .isEmpty ()) {
15351547
15361548 arguments .add ("-D" + ModuleSupport .PROPERTY_IMAGE_EXPLICITLY_ADDED_MODULES + "=" +
@@ -1550,7 +1562,7 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
15501562 }
15511563 }
15521564
1553- arguments .addAll (config . getGeneratorMainClass () );
1565+ arguments .addAll (mainClassArg );
15541566
15551567 if (IS_AOT && OS .getCurrent ().hasProcFS ) {
15561568 /*
@@ -1610,9 +1622,10 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
16101622 switch (ExitStatus .of (exitStatusCode )) {
16111623 case OK -> {
16121624 }
1613- case BUILDER_ERROR ->
1625+ case BUILDER_ERROR -> {
16141626 /* Exit, builder has handled error reporting. */
16151627 throw NativeImage .showError (null , null , exitStatusCode );
1628+ }
16161629 case OUT_OF_MEMORY -> {
16171630 showOutOfMemoryWarning ();
16181631 throw NativeImage .showError (null , null , exitStatusCode );
0 commit comments