On Thu, 15 May 2025 16:42:48 GMT, Jan Lahoda <jlah...@openjdk.org> wrote:
> A consider class like this: > > > public class TwoMains { > private static void main(String... args) {} > static void main() { > System.out.println("Should be called, but is not."); > } > } > > > The `MethodFinder` will do lookup for the `main(String[])` method, and it > finds one, so does not proceed with a lookup for `main()`. But then, it will > check the access modifier, and will reject that method, never going back to > the `main()` method. This is not what the JLS says about the lookup - the > private method is not a candidate, and should be ignored. > > Something similar happens if the return type is not `void`. > > This PR is fixing that by checking whether the `main(String[])` method is > usable early, and falling back to `main()` if it `main(String[])` is not > usable. > > It also removes the check for the `abstract` method, as that, by itself, is > not really backed by JLS, but adds a check for `abstract` class, producing a > user-friendly message is trying to invoke an instance `main` method on an > `abstract` class (which, obviously, cannot be instantiated). test/jdk/tools/launcher/Arrrghs.java line 607: > 605: //private method with parameter, usable method without parameter: > 606: createJar(new File("some.jar"), new File("Foo"), > 607: "private static void main(String[] args){}", Perhaps we should even include a instance method `private void main(String[] args) {}` to cover that case? test/jdk/tools/launcher/Arrrghs.java line 635: > 633: tr.contains("Error: abstract class Foo can not instantiated"); > 634: if (!tr.testStatus) > 635: System.out.println(tr); Hello Jan, I think this is pre-existing, but it looks like we don't fail the test even when `tr.testStatus` indicates a failure? We seem to only write out to `System.out` and return from the test method. Am I misreading the test code? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/25256#discussion_r2092758973 PR Review Comment: https://git.openjdk.org/jdk/pull/25256#discussion_r2092755321