RFR: 8357016: Candidate main methods not computed properly [v4]
Jan Lahoda
jlahoda at openjdk.org
Mon May 19 03:49:20 UTC 2025
> 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).
Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
Adjusting message and tests.
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/25256/files
- new: https://git.openjdk.org/jdk/pull/25256/files/f63dab37..db7e7ceb
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=25256&range=03
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=25256&range=02-03
Stats: 3 lines in 3 files changed: 0 ins; 0 del; 3 mod
Patch: https://git.openjdk.org/jdk/pull/25256.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/25256/head:pull/25256
PR: https://git.openjdk.org/jdk/pull/25256
More information about the core-libs-dev
mailing list