Don't intercept catastrophic errors such as ThreadDeath and OOM.

May fix ticket 206.
This commit is contained in:
Kristian S. Stangeland 2014-03-20 23:26:07 +01:00
parent d76d4247b0
commit bd3a60b7eb
13 changed files with 78 additions and 5 deletions

View File

@ -41,7 +41,7 @@ public class Application {
if (primaryMethod) {
try {
return Bukkit.isPrimaryThread();
} catch (Throwable e) {
} catch (LinkageError e) {
primaryMethod = false;
}
}

View File

@ -242,6 +242,10 @@ public class ProtocolLibrary extends JavaPlugin {
initializeCommands();
setupBroadcastUsers(PERMISSION_INFO);
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
reporter.reportDetailed(this, Report.newBuilder(REPORT_PLUGIN_LOAD_ERROR).error(e).callerParam(protocolManager));
disablePlugin();
@ -263,6 +267,10 @@ public class ProtocolLibrary extends JavaPlugin {
case PACKET:
commandPacket = new CommandPacket(reporter, this, logger, commandFilter, protocolManager); break;
}
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
reporter.reportWarning(this, Report.newBuilder(REPORT_CANNOT_REGISTER_COMMAND).
messageParam(command.name(), e.getMessage()).error(e));
@ -395,6 +403,10 @@ public class ProtocolLibrary extends JavaPlugin {
// It also performs the update check.
createPacketTask(server);
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
reporter.reportDetailed(this, Report.newBuilder(REPORT_PLUGIN_ENABLE_ERROR).error(e));
disablePlugin();
@ -406,6 +418,10 @@ public class ProtocolLibrary extends JavaPlugin {
if (config.isMetricsEnabled()) {
statistisc = new Statistics(this);
}
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (IOException e) {
reporter.reportDetailed(this, Report.newBuilder(REPORT_METRICS_IO_ERROR).error(e).callerParam(statistisc));
} catch (Throwable e) {
@ -537,6 +553,10 @@ public class ProtocolLibrary extends JavaPlugin {
}
}, ASYNC_MANAGER_DELAY, ASYNC_MANAGER_DELAY);
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
if (packetTask == -1) {
reporter.reportDetailed(this, Report.newBuilder(REPORT_CANNOT_CREATE_TIMEOUT_TASK).error(e));
@ -628,7 +648,13 @@ public class ProtocolLibrary extends JavaPlugin {
try {
log = getLogger();
} catch (Throwable e) { }
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
// Ignore
}
// Use the default logger instead
if (log == null)

View File

@ -604,6 +604,10 @@ public class AsyncListenerHandler {
}
}
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
// Minecraft doesn't want your Exception.
filterManager.getErrorReporter().reportMinimal(listener.getPlugin(), methodName, e);

View File

@ -125,7 +125,7 @@ public class DetailedErrorReporter implements ErrorReporter {
private static Logger getBukkitLogger() {
try {
return Bukkit.getLogger();
} catch (Throwable e) {
} catch (LinkageError e) {
return Logger.getLogger("Minecraft");
}
}
@ -418,7 +418,7 @@ public class DetailedErrorReporter implements ErrorReporter {
try {
if (!apacheCommonsMissing)
return (ToStringBuilder.reflectionToString(value, ToStringStyle.MULTI_LINE_STYLE, false, null));
} catch (Throwable ex) {
} catch (LinkageError ex) {
// Apache is probably missing
apacheCommonsMissing = true;
}

View File

@ -141,6 +141,10 @@ public class PacketConstructor {
try {
result = unwrapper.unwrapItem(values[i]);
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
lastException = e;
}

View File

@ -238,6 +238,10 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
// The plugin verifier - we don't want to stop ProtocolLib just because its failing
try {
this.pluginVerifier = new PluginVerifier(builder.getLibrary());
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
reporter.reportWarning(this, Report.newBuilder(REPORT_PLUGIN_VERIFIER_ERROR).
messageParam(e.getMessage()).error(e));

View File

@ -156,6 +156,11 @@ class ReadPacketModifier implements MethodInterceptor {
override.put(thisObj, result);
}
}
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
// Minecraft cannot handle this error
reporter.reportDetailed(this,

View File

@ -120,6 +120,10 @@ public class WritePacketModifier implements MethodInterceptor {
output.write(outputBuffer);
return null;
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
// Minecraft cannot handle this error
reporter.reportDetailed(this,

View File

@ -359,6 +359,10 @@ public class InjectedServerConnection {
// If so, copy the content of the old element to the new
try {
writer.copyTo(inserting, replacement, inserting.getClass());
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
reporter.reportDetailed(InjectedServerConnection.this,
Report.newBuilder(REPORT_CANNOT_COPY_OLD_TO_NEW).messageParam(inserting).callerParam(inserting, replacement).error(e)

View File

@ -86,6 +86,10 @@ class NetLoginInjector {
// NetServerInjector can never work (currently), so we don't need to replace the NetLoginHandler
return inserting;
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
// Minecraft can't handle this, so we'll deal with it here
reporter.reportDetailed(this,
@ -129,6 +133,10 @@ class NetLoginInjector {
}
}
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
// Don't leak this to Minecraft
reporter.reportDetailed(this,

View File

@ -221,6 +221,10 @@ class NetworkServerInjector extends PlayerInjector {
if (proxyServerField != null && !proxyServerField.equals(serverHandlerRef.getField())) {
try {
return FieldUtils.readField(proxyServerField, serverHandler, true);
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
// Oh well
}

View File

@ -642,6 +642,10 @@ public abstract class PlayerInjector implements SocketInjector {
return result;
}
} catch (OutOfMemoryError e) {
throw e;
} catch (ThreadDeath e) {
throw e;
} catch (Throwable e) {
reporter.reportDetailed(this, Report.newBuilder(REPORT_CANNOT_HANDLE_PACKET).error(e).callerParam(packet));
}

View File

@ -221,6 +221,12 @@ public class BackgroundCompiler {
}
}
} catch (OutOfMemoryError e) {
setEnabled(false);
throw e;
} catch (ThreadDeath e) {
setEnabled(false);
throw e;
} catch (Throwable e) {
// Disable future compilations!
setEnabled(false);