zoukankan      html  css  js  c++  java
  • 坑爹的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

  • 相关阅读:
    为什么我的Android SDK Manager中只显示已安装的package?
    解决Android Studio Gradle Build特别慢的问题
    一款不错的取色器
    Android Studio没有导包快捷键怎么办
    Android Studio中有没有类似于Eclipse中的ctrl+2+L的快捷键? Android Studio快捷键之代码提示
    安卓动画总结【非原创】
    ButterKnife-5.1.2.jar(较低版本的ButterKnife)使用方法
    【转】调用getActionBar()报Call requires API level 11 (current min is 8): android.app.Activity#getActionBar
    spring容器加载完毕做一件事情(利用ContextRefreshedEvent事件)转
    详解 Spring 3.0 基于 Annotation 的依赖注入实现(转)
  • 原文地址:https://www.cnblogs.com/zollty/p/3396252.html
Copyright © 2011-2022 走看看