坑爹的Sun JDK

 

Sun的这个java.lang.Throwable 源码 设计非常糟糕,完全没有扩展性,

 

我在IBM 的Java JDK下,继承java.lang.Throwable重新定义了一个ExceptionWrapper,重载了java.lang.Throwable的大部分方法,

目的就是,不用Java本身的那种堆栈信息,大家知道的,Java本身的堆栈信息冗余性非常大,点击一个Action报错就上百行,当时真正有价值的错误信息就几行。

 

IBM的JDK是可以重写java.lang.Throwable的方法的,但是Sun的JDK坑爹的是private的方法,重写不了!这种设计真是坑爹。

不只是我遇到这个问题,网上也有人再说,问题的详细描述如下:

Hello java gods!  I've no idea, whether this is the right forum to post my request to, but I hope, some sun java developers will read it and may be able to do the following change:  class Throwable, method void printStackTraceAsCause(PrintStream s, StackTraceElement[] causedTrace)  and  class Throwable, method void printStackTraceAsCause(PrintWriter s, StackTraceElement[] causedTrace)  are both declared private. This should be protected, because we are developing a client server environment where exceptions are transferred over the network and for several reasons, I use a special own StackTraceElement. This is necessary, because the original StackTraceElements are created "magically" by the VM and cannot be constructed by normal code. Additionally, I need more information and have added fields to my own RemoteStackTraceElement.  Well, if the above methods were protected instead of private, it would always execute my methods instead of the original ones, if one of my Exceptions is in the list of causes. This means, I could encapsulate my exception the following way, which is sometimes needed, e.g. in Listeners:  void methodGivenByInterface() throws ExceptionGivenByInterface {   try {     client.execCmd(...);   } catch (RemoteException x) {     throw new ExceptionGivenByInterface(x);   } }  If the method that executes myMethod does a printStackTrace, it executes the one of ExceptionGivenByInterface. Because my RemoteException is the cause, the printStackTraceAsCause of it will be executed. But because it is declared private in Throwable, it does not execute my own printStackTraceAsCause but the one of Throwable.  I hope, I could make clear, why it is necessary to change private to protected, and I hope, someone finds the time to change this one word at both methods   Thousand thanks in advance for getting a protected Throwable.printStackTraceAsCause in j2sdk1.5x!  Best regards, Marco

 

 

 

posted @ 2013-10-30 11:07  Zollty  阅读(367)  评论(3编辑  收藏  举报