[java] IDEA-375134 Can't run non-static main method for Java 21 Preview

(cherry picked from commit f9d8a7a3b8b6f24ae8014ffb05b9b5b28ba9d3c0)


(cherry picked from commit f0966f81713bd81f4128c2a1c1fbd717dc394682)

IJ-MR-169535

GitOrigin-RevId: f9bfafb5e635f684d124d8fd4a7a5a996c6971e7
This commit is contained in:
Mikhail Pyltsin
2025-06-27 16:16:17 +02:00
committed by intellij-monorepo-bot
parent 5fa62ff23e
commit bc7eb9f89f

View File

@@ -120,10 +120,12 @@ public final class AppMainV2 {
* - MainMethodStatus.WithoutArgs: the method is the main method and does not accept any parameters
*/
private static MainMethodStatus getMainMethodStatus(Method method, MainMethodSearchMode mode) {
if ("main".equals(method.getName()) ) {
if ("main".equals(method.getName())) {
if (!Modifier.isPrivate(method.getModifiers())) {
if (mode == MainMethodSearchMode.ALL_METHOD ||
(mode == MainMethodSearchMode.STATIC_METHOD && Modifier.isStatic(method.getModifiers()))) {
(mode == MainMethodSearchMode.STATIC_METHOD && Modifier.isStatic(method.getModifiers())) ||
(mode == MainMethodSearchMode.NON_STATIC_METHOD && !Modifier.isStatic(method.getModifiers()))
) {
Class<?>[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length == 1 && parameterTypes[0] == String[].class) {
return MainMethodStatus.WithArgs;