i have following simple java code :
try { - processbuilder pb = new processbuilder("thebatchfile.bat", "argument1", "argument2"); pb.directory(new file("/path/to/working/dir")); process p = pb.start(); p.waitfor(); } catch ( ioexception e) { system.out.println(thread.currentthread().getstacktrace()); system.out.println("heres line"); system.out.println(e.getstacktrace() ) ; system.out.println (" print-statement after stacktrace"); }
and when run twice in row , return different results. here's output:
[ljava.lang.stacktraceelement;@fe64b9 heres line [ljava.lang.stacktraceelement;@186db54 print-statement after stacktrace
i curious going on here - why that, though compiled it, , run same code, still give different results getstacktrace()
the getstacktrace()
method defined in throwable
class (the superclass of exception
s) as:
public stacktraceelement[] getstacktrace() { return getourstacktrace().clone(); }
so each time invoked (whether using exception#getstacktrace()
or using thread#getstacktrace()
), return new object. hence new hash code expected printed.
Comments
Post a Comment