/*
 * Copyright 2016-2020 Chronicle Software
 *
 * https://chronicle.software
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.openhft.chronicle.core;

/**
 * Throwable created purely for the purposes of reporting a stack trace.
 * <p>
 * This is not an Error or an Exception and is not expected to be thrown or caught.
 * </p>
 * https://github.com/OpenHFT/Chronicle-Core/issues/75
 */
public class StackTrace extends Throwable {
    public StackTrace() {
        this("stack trace");
    }

    public StackTrace(String message) {
        this(message, null);
    }

    public StackTrace(String message, Throwable cause) {
        super(message + " on " + Thread.currentThread().getName(), cause);
    }

    public static StackTrace forThread(Thread t) {
        StackTrace st = new StackTrace(t.toString());
        st.setStackTrace(t.getStackTrace());
        return st;
    }
}

@@ -672,16 +672,60 @@
 .core;%0A%0A
+import org.jetbrains.annotations.Nullable;%0A%0A
 /**%0A * T
@@ -1264,32 +1264,46 @@
  cause);%0A    %7D%0A%0A
+    @Nullable%0A
     public stati
@@ -1333,24 +1333,60 @@
 Thread t) %7B%0A
+        if (t == null) return null;%0A
         Stac
@@ -1439,44 +1439,323 @@
     
-st.setStackTrace(t.getStackTrace());
+StackTraceElement%5B%5D stackTrace = t.getStackTrace();%0A        if (stackTrace.length %3E= 2) %7B%0A            StackTraceElement%5B%5D stackTrace2 = new StackTraceElement%5BstackTrace.length - 2%5D;%0A            System.arraycopy(stackTrace, 2, stackTrace2, 0, stackTrace2.length);%0A            st.setStackTrace(stackTrace2);%0A        %7D
 %0A   

Tidy up resources in CQE