On Mon, 1 May 2023 13:06:24 GMT, Jim Laskey <jlas...@openjdk.org> wrote:

>> Add flexible main methods and anonymous main classes to the Java language.
>
> Jim Laskey has updated the pull request incrementally with two additional 
> commits since the last revision:
> 
>  - Anonymous main classes renamed to unnamed classes
>  - Add test

src/java.base/share/classes/sun/launcher/LauncherHelper.java line 872:

> 870:         Method mainMethod = null;
> 871:         try {
> 872:             mainMethod = MainMethodFinder.findMainMethod(mainClass);

The `MainMethodFinder.findMainMethod(...)` throws a `NoSuchMethodException` 
when it can't find the regular `public static void main(String[])` or, when 
preview is enabled, any other eligible main methods. That will now mean that 
the next line here which catches a `NoSuchMethodException` can potentially end 
up aborting with a (very confusing) error message about JavaFX application. We 
should perhaps change that catch block to something like:

} catch (NoSuchMethodException nsme) {
   if (!PreviewFeatures.isEnabled()) {
                  // invalid main or not FX application, abort with an error
            abort(null, "java.launcher.cls.error4", mainClass.getName(),
                  JAVAFX_APPLICATION_CLASS_NAME);
   } else {
       // abort with something more clear error?
   }

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13689#discussion_r1185905158

Reply via email to