From b8cde09c4da97a6021ead68986cc1421b25c68bf Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Wed, 10 Apr 2024 15:41:20 +0800 Subject: [PATCH] fix Java 22 main method searching order --- .../internal/ResolveMainMethodHandler.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainMethodHandler.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainMethodHandler.java index fb8dfc33..be1092bb 100644 --- a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainMethodHandler.java +++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainMethodHandler.java @@ -142,23 +142,15 @@ private static boolean isInstanceMainMethodSupported(IType type) { return CompilerOptions.versionToJdkLevel(options.get(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM)) >= ClassFileConstants.JDK21; } + /** + * See Java 22 JEP 463 https://openjdk.org/jeps/463. + * It searches the main method in the launched class by following a specific order: + * - If the launched class contains a main method with a String[] parameter then choose that method. + * - Otherwise, if the class contains a main method with no parameters then choose that method. + */ private static int getMainMethodPriority(IMethod method) { - int flags = 0; - try { - flags = method.getFlags(); - } catch (JavaModelException e) { - // do nothing - } String[] params = method.getParameterTypes(); - if (Flags.isStatic(flags) && params.length == 1) { - return 1; - } else if (Flags.isStatic(flags)) { - return 2; - } else if (params.length == 1) { - return 3; - } - - return 4; + return params.length == 1 ? 1 : 2; } private static List getPotentialMainClassTypes(ICompilationUnit compilationUnit) throws JavaModelException {