ExtendedStackTraceElement [ ] toExtendedStackTrace ( final Stack < Class < ? > > stack , final Map < String , CacheEntry > map , final StackTraceElement [ ] rootTrace , final StackTraceElement [ ] stackTrace ) { int stackLength ; if ( rootTrace != null ) { int rootIndex = rootTrace . length - 1 ; int stackIndex = stackTrace . length - 1 ; while ( rootIndex >= 0 && stackIndex >= 0 && rootTrace [ rootIndex ] . equals ( stackTrace [ stackIndex ] ) ) { -- rootIndex ; -- stackIndex ; } this . commonElementCount = stackTrace . length - 1 - stackIndex ; stackLength = stackIndex + 1 ; } else { this . commonElementCount = 0 ; stackLength = stackTrace . length ; } final ExtendedStackTraceElement [ ] extStackTrace = new ExtendedStackTraceElement [ stackLength ] ; Class < ? > clazz = stack . isEmpty ( ) ? null : stack . peek ( ) ; ClassLoader lastLoader = null ; for ( int i = stackLength - 1 ; i >= 0 ; -- i ) { final StackTraceElement stackTraceElement = stackTrace [ i ] ; final String className = stackTraceElement . getClassName ( ) ; // The stack returned from getCurrentStack may be missing entries for java.lang.reflect.Method.invoke() // and its implementation. The Throwable might also contain stack entries that are no longer // present as those methods have returned. ExtendedClassInfo extClassInfo ; if ( clazz != null && className . equals ( clazz . getName ( ) ) ) { final CacheEntry entry = this . toCacheEntry ( stackTraceElement , clazz , true ) ; extClassInfo = entry . element ; lastLoader = entry . loader ; stack . pop ( ) ; clazz = stack . isEmpty ( ) ? null : stack . peek ( ) ; } else { final CacheEntry cacheEntry = map . get ( className ) ; if ( cacheEntry != null ) { final CacheEntry entry = cacheEntry ; extClassInfo = entry . element ; if ( entry . loader != null ) { lastLoader = entry . loader ; } } else { final CacheEntry entry = this . toCacheEntry ( stackTraceElement , this . loadClass ( lastLoader , className ) , false ) ; extClassInfo = entry . element ; map . put ( stackTraceElement . toString ( ) , entry ) ; if ( entry . loader != null ) { lastLoader = entry . loader ; } } } extStackTrace [ i ] = new ExtendedStackTraceElement ( stackTraceElement , extClassInfo ) ; } return extStackTrace ; }
Resolve all the stack entries in this stack trace that are not common with the parent .