Home | History | Annotate | Download | only in base
      1 /*
      2  * Copyright (c) 2007 Mockito contributors
      3  * This program is made available under the terms of the MIT License.
      4  */
      5 
      6 package org.mockito.exceptions.base;
      7 
      8 import org.mockito.internal.exceptions.stacktrace.ConditionalStackTraceFilter;
      9 
     10 import java.io.ObjectStreamException;
     11 
     12 /**
     13  * Raised by mockito to emit an error either due to Mockito, or due to the User.
     14  *
     15  * <p>
     16  *     The stack trace is filtered from mockito calls if you are using {@link #getStackTrace()}.
     17  *     For debugging purpose though you can still access the full stacktrace using {@link #getUnfilteredStackTrace()}.
     18  *     However note that other calls related to the stackTrace will refer to the filter stacktrace.
     19  * </p>
     20  *
     21  * @since 1.10.0
     22  */
     23 public class MockitoSerializationIssue extends ObjectStreamException {
     24 
     25     private StackTraceElement[] unfilteredStackTrace;
     26 
     27     public MockitoSerializationIssue(String message, Exception cause) {
     28         super(message);
     29         initCause(cause);
     30         filterStackTrace();
     31     }
     32 
     33     private void filterStackTrace() {
     34         unfilteredStackTrace = super.getStackTrace();
     35 
     36         ConditionalStackTraceFilter filter = new ConditionalStackTraceFilter();
     37         filter.filter(this);
     38     }
     39 
     40     public StackTraceElement[] getUnfilteredStackTrace() {
     41         return unfilteredStackTrace;
     42     }
     43 }
     44