RFR: JDK-8306112 Implementation of JEP 445: Unnamed Classes and Instance Main Methods (Preview) [v8]

Jaikiran Pai jpai at openjdk.org
Fri May 5 09:55:23 UTC 2023

On Mon, 1 May 2023 13:06:24 GMT, Jim Laskey <jlaskey at 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(),
   } else {
       // abort with something more clear error?


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

More information about the compiler-dev mailing list