A DESCRIPTION OF THE REQUEST : intCause() is a new mechanism for chaining in JDK 1.4. In pre-1.4 version the cause was recieved in the constructor in major cases. There are two main usage of it, in the constructor of custom exception that receive cause or immediately after exception is initialize, initCause() was called to add the cause. The last one was used with "legacy exception" primarily, but not only. There problem is in last usage. initCause() returns Throwable, so explicit casting is needed. For example, throw (AssertionError)new AssertionError("UnexpectedException occured. ").initCause(e). Otherwise, compiler is thinking that not AssertionError is thrown, but Throwable with all complications. I suggest to change Throwable, perhaps with use of generic, so initCause() will return this type, rather then Throwable, in order to avoid casting. JUSTIFICATION : Generic make significant step in type safety. It is needed to make on more little step to remove unnecessary casting from initCause(). CUSTOMER SUBMITTED WORKAROUND : try{ doSomething(); }catch (Exception e){ log.error("Something goes wrong, while it should be ok",e); throw (AssertionError)new AssertionError("UnexpectedException occured. ").initCause(e); }
|