All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fi.jumi.core.api.StackTrace Maven / Gradle / Ivy

There is a newer version: 0.5.437
Show newest version
// Copyright © 2011-2013, Esko Luontola 
// This software is released under the Apache License 2.0.
// The license text is at http://www.apache.org/licenses/LICENSE-2.0

package fi.jumi.core.api;

import javax.annotation.concurrent.ThreadSafe;

/**
 * Masquerades as another exception instance. Enables transferring exception stack traces between JVMs, without
 * requiring the remote JVM to have every custom exception class on its classpath.
 */
@ThreadSafe
public class StackTrace extends Throwable {

    private final String exceptionClass;
    private final String toString;

    public static StackTrace copyOf(Throwable original) {
        if (original == null) {
            return null;
        }
        return new StackTrace(original);
    }

    private StackTrace(Throwable original) {
        super(original.getMessage(), copyOf(original.getCause()));
        exceptionClass = original.getClass().getName();
        toString = original.toString();
        setStackTrace(original.getStackTrace());
        for (Throwable suppressed : original.getSuppressed()) {
            addSuppressed(copyOf(suppressed));
        }
    }

    @Override
    public synchronized Throwable fillInStackTrace() {
        // Our stack trace will be replaced immediately, so no need to generate it
        return this;
    }

    public String getExceptionClass() {
        return exceptionClass;
    }

    @Override
    public String toString() {
        return toString;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy