Allow Devtools Restarter to work with a parameterless main method

See gh-47987

Signed-off-by: Dmytro Nosan <dimanosan@gmail.com>
This commit is contained in:
Dmytro Nosan
2025-11-09 12:10:26 +01:00
committed by Stéphane Nicoll
parent b9216a05e6
commit bf0152e67c
2 changed files with 34 additions and 14 deletions
@@ -60,7 +60,7 @@ class MainMethod {
private Method getMainMethod(StackTraceElement element) {
try {
Class<?> elementClass = Class.forName(element.getClassName());
Method method = elementClass.getDeclaredMethod("main", String[].class);
Method method = getMainMethod(elementClass);
if (Modifier.isStatic(method.getModifiers())) {
return method;
}
@@ -71,6 +71,15 @@ class MainMethod {
return null;
}
private static Method getMainMethod(Class<?> clazz) throws Exception {
try {
return clazz.getDeclaredMethod("main", String[].class);
}
catch (NoSuchMethodException ex) {
return clazz.getDeclaredMethod("main");
}
}
/**
* Returns the actual main method.
* @return the main method