坑爹的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
- 作者:zollty(接收技术咨询和工作机会)
- 出处:http://www.cnblogs.com/zollty/
- 本文版权归作者和博客园共有,欢迎转载,但请在文章页面明显位置给出原文连接,否则视为侵权。
- 关于博主,85后程序员,擅长复杂分布式系统架构,中间件设计开发,关注效率/性能/稳定性。
- 对于自己,博文只是总结。在总结的过程发现问题,解决问题。
- 对于他人,在此过程如果还能附带帮助他人,那就再好不过了。
- 感谢您的阅读。如果文章对您有用,那么请轻轻点个赞,以资鼓励。