[java, rt] simplify and improve error message

GitOrigin-RevId: 3711bda1c1147443fc8318e19eca7ae1888b620e
This commit is contained in:
Roman Ivanov
2023-09-08 11:29:40 +02:00
committed by intellij-monorepo-bot
parent 9a04255f75
commit f2b1eb4b6a

View File

@@ -109,27 +109,22 @@ public final class AppMainV2 {
try {
declaredConstructor = appClass.getDeclaredConstructor();
} catch (NoSuchMethodException e) {
System.err.println("Class must have constructor with no parameters");
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;
if (Modifier.isStatic(m.getModifiers())) {
if (parameterCount == 0) {
m.invoke(null);
} else {
m.invoke(null, new Object[]{params});
}
} else {
Object objInstance = null;
if (!Modifier.isStatic(m.getModifiers())) {
declaredConstructor.setAccessible(true);
Object objInstance = declaredConstructor.newInstance();
if (parameterCount == 0) {
m.invoke(objInstance);
} else {
m.invoke(objInstance, new Object[]{params});
}
objInstance = declaredConstructor.newInstance();
}
if (parameterCount == 0) {
m.invoke(objInstance);
} else {
m.invoke(objInstance, new Object[]{params});
}
}
catch (InvocationTargetException ite) {