[java, rt] move instantiation to the branch with instance main

GitOrigin-RevId: 485de3c72dec3e0398168201a58cc209283804fd
This commit is contained in:
Roman Ivanov
2023-10-19 13:17:16 +02:00
committed by intellij-monorepo-bot
parent 1edf614aff
commit 2aa38dc112

View File

@@ -105,19 +105,18 @@ public final class AppMainV2 {
return;
}
Constructor<?> declaredConstructor;
try {
declaredConstructor = appClass.getDeclaredConstructor();
} catch (NoSuchMethodException e) {
System.err.println("Non-static main() method was invoked: class must have constructor with no parameters");
return;
}
try {
m.setAccessible(true);
int parameterCount = m.getParameterTypes().length;
Object objInstance = null;
if (!Modifier.isStatic(m.getModifiers())) {
Constructor<?> declaredConstructor;
try {
declaredConstructor = appClass.getDeclaredConstructor();
} catch (NoSuchMethodException e) {
System.err.println("Non-static main() method was invoked: class must have constructor with no parameters");
return;
}
declaredConstructor.setAccessible(true);
objInstance = declaredConstructor.newInstance();
}