diff --git a/src/main/java/world/bentobox/bentobox/BentoBox.java b/src/main/java/world/bentobox/bentobox/BentoBox.java index 8d38ee990..855c56ec2 100644 --- a/src/main/java/world/bentobox/bentobox/BentoBox.java +++ b/src/main/java/world/bentobox/bentobox/BentoBox.java @@ -2,6 +2,7 @@ package world.bentobox.bentobox; import java.util.Optional; +import org.apache.commons.lang.exception.ExceptionUtils; import org.bukkit.Bukkit; import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.PluginManager; @@ -347,6 +348,16 @@ public class BentoBox extends JavaPlugin { getLogger().severe(() -> error); } + /** + * Logs the stacktrace of a Throwable that was thrown by an error. + * It should be used preferably instead of {@link Throwable#printStackTrace()} as it does not risk exposing sensitive information. + * @param throwable the Throwable that was thrown by an error. + * @since 1.3.0 + */ + public void logStacktrace(@NonNull Throwable throwable) { + logError(ExceptionUtils.getStackTrace(throwable)); + } + public void logWarning(String warning) { getLogger().warning(() -> warning); } diff --git a/src/main/java/world/bentobox/bentobox/api/github/GitHubConnector.java b/src/main/java/world/bentobox/bentobox/api/github/GitHubConnector.java index fc4dd9bb8..ead0b6549 100644 --- a/src/main/java/world/bentobox/bentobox/api/github/GitHubConnector.java +++ b/src/main/java/world/bentobox/bentobox/api/github/GitHubConnector.java @@ -5,6 +5,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; +import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.util.Util; import java.io.BufferedReader; @@ -39,8 +40,8 @@ public class GitHubConnector { contributorData = getData("contributors"); releasesData = getData("releases"); } catch (IOException e) { - e.printStackTrace(); - // TODO better logging and do not override data instead + BentoBox.getInstance().logStacktrace(e); + // TODO do not override data instead return; } diff --git a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java index 959c56f73..dbe6ecd72 100644 --- a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java @@ -178,7 +178,7 @@ public class AddonsManager { addon.setState(Addon.State.ERROR); plugin.logError("Skipping " + addon.getDescription().getName() + " due to an unhandled exception..."); // Send stacktrace, required for addon development - plugin.logError(ExceptionUtils.getStackTrace(throwable)); + plugin.logStacktrace(throwable); } /**