Paper/src/main/java/net/minecraft/server/CrashReport.java

236 Zeilen
9.2 KiB
Java

2012-08-18 05:22:20 +02:00
package net.minecraft.server;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
2012-11-06 13:05:28 +01:00
import java.util.ArrayList;
2012-08-18 05:22:20 +02:00
import java.util.Date;
import java.util.Iterator;
2012-11-06 13:05:28 +01:00
import java.util.List;
2012-08-18 05:22:20 +02:00
import java.util.concurrent.Callable;
2013-11-04 14:07:38 +01:00
import net.minecraft.util.org.apache.commons.io.IOUtils;
import net.minecraft.util.org.apache.commons.lang3.ArrayUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2012-08-18 05:22:20 +02:00
public class CrashReport {
2013-11-04 14:07:38 +01:00
private static final Logger a = LogManager.getLogger();
private final String b;
private final Throwable c;
private final CrashReportSystemDetails d = new CrashReportSystemDetails(this, "System Details");
private final List e = new ArrayList();
private File f;
private boolean g = true;
private StackTraceElement[] h = new StackTraceElement[0];
2012-08-18 05:22:20 +02:00
public CrashReport(String s, Throwable throwable) {
2013-11-04 14:07:38 +01:00
this.b = s;
this.c = throwable;
2012-11-06 13:05:28 +01:00
this.h();
2012-08-18 05:22:20 +02:00
}
2012-11-06 13:05:28 +01:00
private void h() {
2013-11-04 14:07:38 +01:00
this.d.a("Minecraft Version", (Callable) (new CrashReportVersion(this)));
this.d.a("Operating System", (Callable) (new CrashReportOperatingSystem(this)));
this.d.a("Java Version", (Callable) (new CrashReportJavaVersion(this)));
this.d.a("Java VM Version", (Callable) (new CrashReportJavaVMVersion(this)));
this.d.a("Memory", (Callable) (new CrashReportMemory(this)));
this.d.a("JVM Flags", (Callable) (new CrashReportJVMFlags(this)));
this.d.a("AABB Pool Size", (Callable) (new CrashReportAABBPoolSize(this)));
this.d.a("IntCache", (Callable) (new CrashReportIntCacheSize(this)));
this.d.a("CraftBukkit Information", (Callable) (new org.bukkit.craftbukkit.CraftCrashReport())); // CraftBukkit
2012-08-18 05:22:20 +02:00
}
public String a() {
2013-11-04 14:07:38 +01:00
return this.b;
2012-08-18 05:22:20 +02:00
}
public Throwable b() {
2013-11-04 14:07:38 +01:00
return this.c;
2012-08-18 05:22:20 +02:00
}
public void a(StringBuilder stringbuilder) {
2013-11-04 14:07:38 +01:00
if ((this.h == null || this.h.length <= 0) && this.e.size() > 0) {
this.h = (StackTraceElement[]) ArrayUtils.subarray(((CrashReportSystemDetails) this.e.get(0)).a(), 0, 1);
}
if (this.h != null && this.h.length > 0) {
2012-11-06 13:05:28 +01:00
stringbuilder.append("-- Head --\n");
stringbuilder.append("Stacktrace:\n");
2013-11-04 14:07:38 +01:00
StackTraceElement[] astacktraceelement = this.h;
2012-11-06 13:05:28 +01:00
int i = astacktraceelement.length;
2012-08-18 05:22:20 +02:00
2012-11-06 13:05:28 +01:00
for (int j = 0; j < i; ++j) {
StackTraceElement stacktraceelement = astacktraceelement[j];
2012-08-18 05:22:20 +02:00
2012-11-06 13:05:28 +01:00
stringbuilder.append("\t").append("at ").append(stacktraceelement.toString());
2012-08-18 05:22:20 +02:00
stringbuilder.append("\n");
}
2012-11-06 13:05:28 +01:00
stringbuilder.append("\n");
2012-08-18 05:22:20 +02:00
}
2012-11-06 13:05:28 +01:00
2013-11-04 14:07:38 +01:00
Iterator iterator = this.e.iterator();
2012-11-06 13:05:28 +01:00
while (iterator.hasNext()) {
CrashReportSystemDetails crashreportsystemdetails = (CrashReportSystemDetails) iterator.next();
crashreportsystemdetails.a(stringbuilder);
stringbuilder.append("\n\n");
}
2013-11-04 14:07:38 +01:00
this.d.a(stringbuilder);
2012-08-18 05:22:20 +02:00
}
public String d() {
StringWriter stringwriter = null;
PrintWriter printwriter = null;
2013-11-04 14:07:38 +01:00
Object object = this.c;
if (((Throwable) object).getMessage() == null) {
if (object instanceof NullPointerException) {
object = new NullPointerException(this.b);
} else if (object instanceof StackOverflowError) {
object = new StackOverflowError(this.b);
} else if (object instanceof OutOfMemoryError) {
object = new OutOfMemoryError(this.b);
}
((Throwable) object).setStackTrace(this.c.getStackTrace());
}
String s = ((Throwable) object).toString();
2012-08-18 05:22:20 +02:00
try {
stringwriter = new StringWriter();
printwriter = new PrintWriter(stringwriter);
2013-11-04 14:07:38 +01:00
((Throwable) object).printStackTrace(printwriter);
2012-08-18 05:22:20 +02:00
s = stringwriter.toString();
} finally {
2013-11-04 14:07:38 +01:00
IOUtils.closeQuietly(stringwriter);
IOUtils.closeQuietly(printwriter);
2012-08-18 05:22:20 +02:00
}
return s;
}
public String e() {
StringBuilder stringbuilder = new StringBuilder();
stringbuilder.append("---- Minecraft Crash Report ----\n");
stringbuilder.append("// ");
2012-11-06 13:05:28 +01:00
stringbuilder.append(i());
2012-08-18 05:22:20 +02:00
stringbuilder.append("\n\n");
stringbuilder.append("Time: ");
stringbuilder.append((new SimpleDateFormat()).format(new Date()));
stringbuilder.append("\n");
stringbuilder.append("Description: ");
2013-11-04 14:07:38 +01:00
stringbuilder.append(this.b);
2012-08-18 05:22:20 +02:00
stringbuilder.append("\n\n");
stringbuilder.append(this.d());
2012-11-06 13:05:28 +01:00
stringbuilder.append("\n\nA detailed walkthrough of the error, its code path and all known details is as follows:\n");
for (int i = 0; i < 87; ++i) {
stringbuilder.append("-");
}
stringbuilder.append("\n\n");
2012-08-18 05:22:20 +02:00
this.a(stringbuilder);
return stringbuilder.toString();
}
2013-11-04 14:07:38 +01:00
public boolean a(File file1) {
if (this.f != null) {
2012-08-18 05:22:20 +02:00
return false;
} else {
if (file1.getParentFile() != null) {
file1.getParentFile().mkdirs();
}
try {
FileWriter filewriter = new FileWriter(file1);
filewriter.write(this.e());
filewriter.close();
2013-11-04 14:07:38 +01:00
this.f = file1;
2012-08-18 05:22:20 +02:00
return true;
} catch (Throwable throwable) {
2013-11-04 14:07:38 +01:00
a.error("Could not save crash report to " + file1, throwable);
2012-08-18 05:22:20 +02:00
return false;
}
}
}
2012-11-06 13:05:28 +01:00
public CrashReportSystemDetails g() {
2013-11-04 14:07:38 +01:00
return this.d;
2012-11-06 13:05:28 +01:00
}
public CrashReportSystemDetails a(String s) {
return this.a(s, 1);
}
public CrashReportSystemDetails a(String s, int i) {
CrashReportSystemDetails crashreportsystemdetails = new CrashReportSystemDetails(this, s);
2013-11-04 14:07:38 +01:00
if (this.g) {
2012-11-06 13:05:28 +01:00
int j = crashreportsystemdetails.a(i);
2013-11-04 14:07:38 +01:00
StackTraceElement[] astacktraceelement = this.c.getStackTrace();
2012-11-06 13:05:28 +01:00
StackTraceElement stacktraceelement = null;
StackTraceElement stacktraceelement1 = null;
2014-03-21 05:26:30 +01:00
int k = astacktraceelement.length - j;
2012-11-06 13:05:28 +01:00
2014-03-21 05:26:30 +01:00
if (k < 0) {
System.out.println("Negative index in crash report handler (" + astacktraceelement.length + "/" + j + ")");
}
if (astacktraceelement != null && 0 <= k && k < astacktraceelement.length) {
stacktraceelement = astacktraceelement[k];
2012-11-06 13:05:28 +01:00
if (astacktraceelement.length + 1 - j < astacktraceelement.length) {
stacktraceelement1 = astacktraceelement[astacktraceelement.length + 1 - j];
}
}
2013-11-04 14:07:38 +01:00
this.g = crashreportsystemdetails.a(stacktraceelement, stacktraceelement1);
if (j > 0 && !this.e.isEmpty()) {
CrashReportSystemDetails crashreportsystemdetails1 = (CrashReportSystemDetails) this.e.get(this.e.size() - 1);
2012-11-06 13:05:28 +01:00
crashreportsystemdetails1.b(j);
2014-03-21 05:26:30 +01:00
} else if (astacktraceelement != null && astacktraceelement.length >= j && 0 <= k && k < astacktraceelement.length) {
2013-11-04 14:07:38 +01:00
this.h = new StackTraceElement[astacktraceelement.length - j];
System.arraycopy(astacktraceelement, 0, this.h, 0, this.h.length);
2012-11-06 13:05:28 +01:00
} else {
2013-11-04 14:07:38 +01:00
this.g = false;
2012-11-06 13:05:28 +01:00
}
}
2013-11-04 14:07:38 +01:00
this.e.add(crashreportsystemdetails);
2012-11-06 13:05:28 +01:00
return crashreportsystemdetails;
}
private static String i() {
2014-03-21 05:26:30 +01:00
String[] astring = new String[] { "Who set us up the TNT?", "Everything\'s going to plan. No, really, that was supposed to happen.", "Uh... Did I do that?", "Oops.", "Why did you do that?", "I feel sad now :(", "My bad.", "I\'m sorry, Dave.", "I let you down. Sorry :(", "On the bright side, I bought you a teddy bear!", "Daisy, daisy...", "Oh - I know what I did wrong!", "Hey, that tickles! Hehehe!", "I blame Dinnerbone.", "You should try our sister game, Minceraft!", "Don\'t be sad. I\'ll do better next time, I promise!", "Don\'t be sad, have a hug! <3", "I just don\'t know what went wrong :(", "Shall we play a game?", "Quite honestly, I wouldn\'t worry myself about that.", "I bet Cylons wouldn\'t have this problem.", "Sorry :(", "Surprise! Haha. Well, this is awkward.", "Would you like a cupcake?", "Hi. I\'m Minecraft, and I\'m a crashaholic.", "Ooh. Shiny.", "This doesn\'t make any sense!", "Why is it breaking :(", "Don\'t do that.", "Ouch. That hurt :(", "You\'re mean.", "This is a token for 1 free hug. Redeem at your nearest Mojangsta: [~~HUG~~]", "There are four lights!", "But it works on my machine."};
2012-08-18 05:22:20 +02:00
try {
return astring[(int) (System.nanoTime() % (long) astring.length)];
} catch (Throwable throwable) {
return "Witty comment unavailable :(";
}
}
2012-11-06 13:05:28 +01:00
public static CrashReport a(Throwable throwable, String s) {
CrashReport crashreport;
if (throwable instanceof ReportedException) {
crashreport = ((ReportedException) throwable).a();
} else {
crashreport = new CrashReport(s, throwable);
}
return crashreport;
}
2012-08-18 05:22:20 +02:00
}