From 66670b647176e9ce4fe503a4ba2bb5f0e443ec03 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Tue, 11 Jun 2024 19:58:29 +0200 Subject: [PATCH] Switch to Throwable for stack trace handling --- .../sosengine/base/logging/CrashHandler.java | 6 ++-- .../sosengine/base/logging/Logger.java | 6 ++-- .../base/logging/LoggerInstance.java | 6 ++-- .../placeholders/crashhandler/Stacktrace.java | 14 ++++----- .../base/utility/StackTraceParser.java | 30 +++++++++---------- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/base/src/main/java/de/staropensource/sosengine/base/logging/CrashHandler.java b/base/src/main/java/de/staropensource/sosengine/base/logging/CrashHandler.java index e79b0fb..e2f5516 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/logging/CrashHandler.java +++ b/base/src/main/java/de/staropensource/sosengine/base/logging/CrashHandler.java @@ -109,10 +109,10 @@ public final class CrashHandler { * * @param logIssuer information about the class that caused the crash * @param message crash error detail - * @param exception simply to provide stacktrace and further insight into the crash, can be set to {@code null} + * @param throwable simply to provide stacktrace and further insight into the crash, can be set to {@code null} * @since 1-alpha0 */ - public static void handleCrash(@NotNull LogIssuer logIssuer, @NotNull String message, @Nullable Exception exception) { + public static void handleCrash(@NotNull LogIssuer logIssuer, @NotNull String message, @Nullable Throwable throwable) { crashed = true; String base = crashTemplate; @@ -133,7 +133,7 @@ public final class CrashHandler { temporaryPlaceholders.add(new IssuerPackage(logIssuer)); temporaryPlaceholders.add(new IssuerPath(logIssuer)); // etc - temporaryPlaceholders.add(new Stacktrace(exception)); + temporaryPlaceholders.add(new Stacktrace(throwable)); // Replace placeholders base = PlaceholderEngine.getInstance().process(base, temporaryPlaceholders); diff --git a/base/src/main/java/de/staropensource/sosengine/base/logging/Logger.java b/base/src/main/java/de/staropensource/sosengine/base/logging/Logger.java index 7622bf8..1e51cc9 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/logging/Logger.java +++ b/base/src/main/java/de/staropensource/sosengine/base/logging/Logger.java @@ -192,11 +192,11 @@ public final class Logger { * * @param logIssuer issuing class * @param message diagnostic message - * @param exception the exception that caused this crash + * @param throwable the throwable that caused this crash * @since 1-alpha0 */ - public static void crash(@NotNull LogIssuer logIssuer, @NotNull String message, @NotNull Exception exception) { - CrashHandler.handleCrash(logIssuer, message, exception); + public static void crash(@NotNull LogIssuer logIssuer, @NotNull String message, @NotNull Throwable throwable) { + CrashHandler.handleCrash(logIssuer, message, throwable); } /** diff --git a/base/src/main/java/de/staropensource/sosengine/base/logging/LoggerInstance.java b/base/src/main/java/de/staropensource/sosengine/base/logging/LoggerInstance.java index 8892fcd..8f7e4f9 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/logging/LoggerInstance.java +++ b/base/src/main/java/de/staropensource/sosengine/base/logging/LoggerInstance.java @@ -119,12 +119,12 @@ public final class LoggerInstance { * Crashes the entire engine. * * @param message the diagnostic message - * @param exception the exception that caused this crash + * @param throwable the throwable that caused this crash * @see CrashHandler * @since 1-alpha0 */ - public void crash(@NotNull String message, @NotNull Exception exception) { - Logger.crash(logIssuer, message, exception); + public void crash(@NotNull String message, @NotNull Throwable throwable) { + Logger.crash(logIssuer, message, throwable); } /** diff --git a/base/src/main/java/de/staropensource/sosengine/base/logging/placeholders/crashhandler/Stacktrace.java b/base/src/main/java/de/staropensource/sosengine/base/logging/placeholders/crashhandler/Stacktrace.java index 89d4c39..7aa5862 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/logging/placeholders/crashhandler/Stacktrace.java +++ b/base/src/main/java/de/staropensource/sosengine/base/logging/placeholders/crashhandler/Stacktrace.java @@ -33,21 +33,21 @@ import org.jetbrains.annotations.Nullable; @SuppressWarnings({ "unused" }) public final class Stacktrace implements Placeholder { /** - * The {@link Exception} to use. + * The {@link Throwable} to use. * * @since 1-alpha0 */ @Nullable - private final Exception exception; + private final Throwable throwable; /** * Constructor. * - * @param exception the {@link Exception} to use + * @param throwable the {@link Throwable} to use * @since 1-alpha0 */ - public Stacktrace(@Nullable Exception exception) { - this.exception = exception; + public Stacktrace(@Nullable Throwable throwable) { + this.throwable = throwable; } /** {@inheritDoc} */ @@ -59,10 +59,10 @@ public final class Stacktrace implements Placeholder { /** {@inheritDoc} */ @Override public @NotNull String replace(@NotNull String text) { - if (exception == null) + if (throwable == null) return text.replace("%" + getName() + "%", "No stacktrace is available."); else { - StackTraceParser stackTraceParser = new StackTraceParser(exception); + StackTraceParser stackTraceParser = new StackTraceParser(throwable); return text.replace("%" + getName() + "%", stackTraceParser.getHeader() + "\n" + stackTraceParser.getStackTrace()); } diff --git a/base/src/main/java/de/staropensource/sosengine/base/utility/StackTraceParser.java b/base/src/main/java/de/staropensource/sosengine/base/utility/StackTraceParser.java index ae787c4..1a6ddec 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/utility/StackTraceParser.java +++ b/base/src/main/java/de/staropensource/sosengine/base/utility/StackTraceParser.java @@ -24,50 +24,50 @@ import lombok.Getter; import org.jetbrains.annotations.NotNull; /** - * Parses the {@link StackTraceElement}s of an {@link Exception} for use in {@link String}. + * Parses the {@link StackTraceElement}s of an {@link Throwable} for use in {@link String}. * - * @see Exception + * @see Throwable * @since 1-alpha0 */ @SuppressWarnings({ "unused", "JavadocBlankLines" }) public class StackTraceParser { /** - * The exception to use. + * The throwable to use. * - * @see Exception + * @see Throwable * @since 1-alpha0 * * -- GETTER -- - * Returns the exception to use. + * Returns the throwable to use. * - * @see Exception + * @see Throwable * @since 1-alpha0 */ @Getter(AccessLevel.PROTECTED) - private final @NotNull Exception exception; + private final @NotNull Throwable throwable; /** * Constructor. * - * @param exception the exception to use + * @param throwable the throwable to use * @since 1-alpha0 */ - public StackTraceParser(@NotNull Exception exception) { - this.exception = exception; + public StackTraceParser(@NotNull Throwable throwable) { + this.throwable = throwable; } /** * Returns the stack trace header.
- * It looks like this: {@code Caused by java.lang.NullPointerException: This application can crash!} + * It looks like this: {@code Caused by java.lang.NullPointerThrowable: This application can crash!} * * @return the stack trace header * @since 1-alpha0 */ public String getHeader() { - if (exception.getMessage() == null) - return "Caused by: " + exception.getClass().getName(); + if (throwable.getMessage() == null) + return "Caused by: " + throwable.getClass().getName(); else - return "Caused by: " + exception.getClass().getName() + ": " + exception.getMessage(); + return "Caused by: " + throwable.getClass().getName() + ": " + throwable.getMessage(); } /** @@ -79,7 +79,7 @@ public class StackTraceParser { public String getStackTrace() { StringBuilder output = new StringBuilder(); - for (StackTraceElement element : exception.getStackTrace()) { + for (StackTraceElement element : throwable.getStackTrace()) { if (!output.isEmpty()) output.append("\n"); output.append("\tat ").append(element.toString()); }