Merge pull request #4830 from kb-1000/unwrap-invocationtargetexception

[NOISSUE] Unwrap InvocationTargetException and allow non-public main classes
This commit is contained in:
Petr Mrázek 2022-07-19 17:23:16 +02:00 committed by GitHub
commit 05e3910fbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,7 @@ import java.applet.Applet;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@ -143,12 +144,14 @@ public class OneSixLauncher implements Launcher
String[] paramsArray = mcparams.toArray(new String[mcparams.size()]);
try
{
mc.getMethod("main", String[].class).invoke(null, (Object) paramsArray);
Method meth = mc.getMethod("main", String[].class);
meth.setAccessible(true);
meth.invoke(null, (Object) paramsArray);
return 0;
} catch (Exception e)
{
Utils.log("Failed to invoke the Minecraft main class:", "Fatal");
e.printStackTrace(System.err);
(e instanceof InvocationTargetException ? e.getCause() : e).printStackTrace(System.err);
return -1;
}
}
@ -195,7 +198,8 @@ public class OneSixLauncher implements Launcher
try
{
meth = mc.getMethod("main", String[].class);
} catch (NoSuchMethodException e)
meth.setAccessible(true);
} catch (NoSuchMethodException | SecurityException e)
{
System.err.println("Failed to acquire the main method:");
e.printStackTrace(System.err);
@ -211,7 +215,7 @@ public class OneSixLauncher implements Launcher
} catch (Exception e)
{
System.err.println("Failed to start Minecraft:");
e.printStackTrace(System.err);
(e instanceof InvocationTargetException ? e.getCause() : e).printStackTrace(System.err);
return -1;
}
return 0;