Skip to content

Commit 83403a4

Browse files
fix Java 22 main method searching order (#548)
1 parent 37d4e66 commit 83403a4

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainMethodHandler.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,15 @@ private static boolean isInstanceMainMethodSupported(IType type) {
142142
return CompilerOptions.versionToJdkLevel(options.get(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM)) >= ClassFileConstants.JDK21;
143143
}
144144

145+
/**
146+
* See Java 22 JEP 463 https://openjdk.org/jeps/463.
147+
* It searches the main method in the launched class by following a specific order:
148+
* - If the launched class contains a main method with a String[] parameter then choose that method.
149+
* - Otherwise, if the class contains a main method with no parameters then choose that method.
150+
*/
145151
private static int getMainMethodPriority(IMethod method) {
146-
int flags = 0;
147-
try {
148-
flags = method.getFlags();
149-
} catch (JavaModelException e) {
150-
// do nothing
151-
}
152152
String[] params = method.getParameterTypes();
153-
if (Flags.isStatic(flags) && params.length == 1) {
154-
return 1;
155-
} else if (Flags.isStatic(flags)) {
156-
return 2;
157-
} else if (params.length == 1) {
158-
return 3;
159-
}
160-
161-
return 4;
153+
return params.length == 1 ? 1 : 2;
162154
}
163155

164156
private static List<IType> getPotentialMainClassTypes(ICompilationUnit compilationUnit) throws JavaModelException {

0 commit comments

Comments
 (0)