Showing posts from April, 2014

Java forge a stack trace.

Forging a stack trace in java The java.lang.Throwable.setStackTrace() method sets the stack trace elements that will be returned by getStackTrace() and printed by printStackTrace() and related methods. The signature of the method is below. public void setStackTrace(StackTraceElement[] stackTrace) This method can be used to modify the actual stack trace. When do you want to modify the original stack trace? There are certain scenarios when the application developer decides to append, prepend or curtail the original stack trace. Java RMI implementation constructs a stack trace by prepending the remote stack trace. Some libraries merge the stack traces from different sources which are all can be a reason for current stack trace. Sometimes you do not want the larger stack trace information to go into logs.   For example an application which handles validation errors by means of java exception chaining will log the validation error and print the stack trac