public StackTraceElement [ ] getStackTraceEliminatingDuplicateFrames ( ) { // If this isn't a cause, there can't be any duplicate frames, so proceed no further if ( parentFrames == null ) { return getStackTrace ( ) ; } if ( noduplicatesStackTrace == null ) { List < StackTraceElement > list = new ArrayList < StackTraceElement > ( ) ; // Only put the comment saying there are other classes in the stack if there actually are, // and if this isn't a 'cause' exception StackTraceElement [ ] stackElements = getStackTrace ( ) ; // Now do a second trimming, if necessary, to eliminate any duplication in 'caused by' traces int numberToInclude = countNonDuplicatedFrames ( parentFrames , stackElements ) ; for ( int i = 0 ; i < numberToInclude ; i ++ ) { list . add ( stackElements [ i ] ) ; } // Only put the comment saying there are other classes in the stack if there actually are boolean duplicateFramesRemoved = numberToInclude < stackElements . length ; if ( duplicateFramesRemoved ) { // Use shonky eyecatchers since we can't subclass StackTraceElement list . add ( new StackTraceElement ( "... " + ( stackElements . length - numberToInclude ) + " more" , DUPLICATE_FRAMES_EYECATCHER , null , 0 ) ) ; } noduplicatesStackTrace = list . toArray ( new StackTraceElement [ 0 ] ) ; } return noduplicatesStackTrace . clone ( ) ; }
Useful for exceptions which are the causes of other exceptions . Gets the stack frames but not only does it eliminate internal classes it eliminates frames which are redundant with the parent exception . In the case where the exception is not a cause it returns a normal exception . If duplicate frames are stripped it will add an