0

Consider a scenario where a java application error occurs and all you can see is an exception stack trace. Now, if you can re-create this issue somehow and turn your replay logs on, then use this replay log file to inject the exactly same state due to which the exception happened . I want to know if there an existing java library which can be used to do such a thing. Or Is it like will have to design my application such that it can cater to such requirements ?

For example consider the following class and the output. Now after parsing the output and using reflection I can exactly replay the div by 0 scenario.

So would like to know if there an existing java library which provides such functionality ?

public class MyClass {

    /**
     * @param args
     */

    public static void main(String[] args) {
        MyClass myClass = new MyClass();
        //Scenario 1
        int div1 = myClass.div(1,2);
        int div2 = myClass.div(1,0);


    }

    public int div(int firstArg,int secondArg){
        log(firstArg + "," + secondArg);
        return firstArg / secondArg;
    }

    private void log(String args){
        StringBuffer sb = new StringBuffer();
        sb.append("\nClass " + getClass().getName());
        sb.append(" Method " + getMethodName(1));
        sb.append(" Args " + args);
        System.out.println("LOG # " + sb.toString());
    }

    // picked from http://stackoverflow.com/questions/442747/getting-the-name-of-the-current-executing-method
    public static String getMethodName(final int depth)
    {
      final StackTraceElement[] ste = Thread.currentThread().getStackTrace();

      return ste[ste.length - 1 - depth].getMethodName(); //Thank you Tom Tresansky
    }

}

**

LOG # 
Class MyClass Method div Args 1,2
Exception in thread "main" LOG # 
Class MyClass Method div Args 1,0
java.lang.ArithmeticException: / by zero
    at MyClass.div(MyClass.java:19)
    at MyClass.main(MyClass.java:12)

**

Shakti
  • 2,013
  • 8
  • 27
  • 40

1 Answers1

1

CChronon is the solution. For Chronon, you have to buy licence,.or you can use Chronon plugin with intellij idea ultimate for free.

http://blog.jetbrains.com/idea/2014/03/try-chronon-debugger-with-intellij-idea-13-1-eap/?_ga=1.102962688.1259655133.1391072454 is the solution for you!

Chamil
  • 805
  • 5
  • 12