public static StackTraceElement [ ] getStackTrace ( final Throwable t , final String [ ] allow , final String [ ] deny ) { StackTraceElement [ ] st = t . getStackTrace ( ) ; ArrayList < StackTraceElement > result = new ArrayList <> ( st . length ) ; elementLoop : for ( StackTraceElement element : st ) { String className = element . getClassName ( ) ; if ( allow != null ) { boolean validElemenet = false ; for ( String filter : allow ) { if ( className . contains ( filter ) ) { validElemenet = true ; break ; } } if ( ! validElemenet ) { continue ; } } if ( deny != null ) { for ( String filter : deny ) { if ( className . contains ( filter ) ) { continue elementLoop ; } } } result . add ( element ) ; } st = new StackTraceElement [ result . size ( ) ] ; return result . toArray ( st ) ; }
Returns stack trace filtered by class names .