This PVS award goes to the developer of this  code (sanitized to avoid NDA violations).  While trying to troubleshoot  an issue one day, the stack trace was always null.  Huh?  null stack  trace?  How does that happen?  
The following class is in a  shared library jar, and is used as the base class for many different  application-specific exception classes in several apps.
  
public  class MYException extends Exception {
...
    public  MyException(String message, Throwable cause) {
         super(message);
        initializeCause(cause);
    }
     public Throwable initializeCause(Throwable cause)  throws  IllegalArgumentException IllegalStateException {
        // ... some  code here that conditionally throws those exceptions depending on what  cause is, followed by this gem... \\
        mCause = cause;
         mStackTrace = null;  // clear a stack trace
        return this;
     }
... 
    public void printStackTrace() {  printStackTrace(System.err); }
    public void  printStackTrace(PrintStream stream) {
        if (mStackTrace !=  null) {
            super.printStackTrace();
            if  (mCause != null) {
                stream.print("Caused by: ");
                 mCause.PrintStackTrace();
            }
        }  else {
            stream.print(mStackTrace);
        }
    }
So  printStackTrace always prints null.
 
 
 
No comments:
Post a Comment