Explicitly log exception from asynchronous tasks.

Previously an UnhandledException would be thrown and the stack trace / message would be printed to System.err in the default UncaughtExceptionHandler for ThreadGroup. This was undesirable as it meant that logging frameworks / exception monitors such as Sentry were unable to get the exception. Additionally it would cause the death of the thread in the ExecutorService. This change mimics the behaviour of exceptions occuring during synchronous tasks.
This commit is contained in:
hibo98 2016-10-24 18:47:47 +11:00 committed by md_5
parent 2e39de698d
commit 251a5b6382

View File

@ -3,12 +3,11 @@ package org.bukkit.craftbukkit.scheduler;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import org.apache.commons.lang.UnhandledException;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitWorker; import org.bukkit.scheduler.BukkitWorker;
class CraftAsyncTask extends CraftTask { class CraftAsyncTask extends CraftTask {
private final LinkedList<BukkitWorker> workers = new LinkedList<BukkitWorker>(); private final LinkedList<BukkitWorker> workers = new LinkedList<BukkitWorker>();
@ -53,7 +52,8 @@ class CraftAsyncTask extends CraftTask {
super.run(); super.run();
} catch (final Throwable t) { } catch (final Throwable t) {
thrown = t; thrown = t;
throw new UnhandledException( getOwner().getLogger().log(
Level.WARNING,
String.format( String.format(
"Plugin %s generated an exception while executing task %s", "Plugin %s generated an exception while executing task %s",
getOwner().getDescription().getFullName(), getOwner().getDescription().getFullName(),