java - Why property ''cause" of Exception is repeating forever? -
while debugging eclipse ide httpclienterrorexception noticed property "cause" contains reference error itself, went through , there property "cause" again, , again ... forever.
why property contains reference itself?
throwable
declares
private throwable cause = this;
if cause not initialized, either passing cause in constructor or calling initcause
, continue point this
. note consequently getcause
implemented as:
public synchronized throwable getcause() { return (cause==this ? null : cause); }
update:
the reason design explained in throwable
:
to allow throwable objects made immutable , safely reused jvm, such outofmemoryerrors, fields of throwable writable in response user actions, cause, stacktrace, , suppressedexceptions obey following protocol:
1) fields initialized non-null sentinel value indicates value has logically not been set.
2) writing null field indicates further writes forbidden
3) sentinel value may replaced non-null value.
for example, implementations of hotspot jvm have preallocated outofmemoryerror objects provide better diagnosability of situation. these objects created without calling constructor class , fields in question initialized null. support capability, new fields added throwable require being initialized non-null value require coordinated jvm change.
Comments
Post a Comment