Serialization and printStackTrace commented out for now emul
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 30 Sep 2012 17:42:21 -0700
branchemul
changeset 8389b2cb4068fc
parent 82 e8ffc304d302
child 84 d65b3a2fbfaf
Serialization and printStackTrace commented out for now
emul/src/main/java/java/lang/Throwable.java
     1.1 --- a/emul/src/main/java/java/lang/Throwable.java	Sun Sep 30 17:40:28 2012 -0700
     1.2 +++ b/emul/src/main/java/java/lang/Throwable.java	Sun Sep 30 17:42:21 2012 -0700
     1.3 @@ -629,137 +629,137 @@
     1.4       *          ... 2 more
     1.5       * </pre>
     1.6       */
     1.7 -    public void printStackTrace() {
     1.8 -        printStackTrace(System.err);
     1.9 -    }
    1.10 -
    1.11 -    /**
    1.12 -     * Prints this throwable and its backtrace to the specified print stream.
    1.13 -     *
    1.14 -     * @param s {@code PrintStream} to use for output
    1.15 -     */
    1.16 -    public void printStackTrace(PrintStream s) {
    1.17 -        printStackTrace(new WrappedPrintStream(s));
    1.18 -    }
    1.19 -
    1.20 -    private void printStackTrace(PrintStreamOrWriter s) {
    1.21 -        // Guard against malicious overrides of Throwable.equals by
    1.22 -        // using a Set with identity equality semantics.
    1.23 -//        Set<Throwable> dejaVu =
    1.24 -//            Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
    1.25 -//        dejaVu.add(this);
    1.26 -
    1.27 -        synchronized (s.lock()) {
    1.28 -            // Print our stack trace
    1.29 -            s.println(this);
    1.30 -            StackTraceElement[] trace = getOurStackTrace();
    1.31 -            for (StackTraceElement traceElement : trace)
    1.32 -                s.println("\tat " + traceElement);
    1.33 -
    1.34 -            // Print suppressed exceptions, if any
    1.35 +//    public void printStackTrace() {
    1.36 +//        printStackTrace(System.err);
    1.37 +//    }
    1.38 +//
    1.39 +//    /**
    1.40 +//     * Prints this throwable and its backtrace to the specified print stream.
    1.41 +//     *
    1.42 +//     * @param s {@code PrintStream} to use for output
    1.43 +//     */
    1.44 +//    public void printStackTrace(PrintStream s) {
    1.45 +//        printStackTrace(new WrappedPrintStream(s));
    1.46 +//    }
    1.47 +//
    1.48 +//    private void printStackTrace(PrintStreamOrWriter s) {
    1.49 +//        // Guard against malicious overrides of Throwable.equals by
    1.50 +//        // using a Set with identity equality semantics.
    1.51 +////        Set<Throwable> dejaVu =
    1.52 +////            Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
    1.53 +////        dejaVu.add(this);
    1.54 +//
    1.55 +//        synchronized (s.lock()) {
    1.56 +//            // Print our stack trace
    1.57 +//            s.println(this);
    1.58 +//            StackTraceElement[] trace = getOurStackTrace();
    1.59 +//            for (StackTraceElement traceElement : trace)
    1.60 +//                s.println("\tat " + traceElement);
    1.61 +//
    1.62 +//            // Print suppressed exceptions, if any
    1.63 +////            for (Throwable se : getSuppressed())
    1.64 +////                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
    1.65 +//
    1.66 +//            // Print cause, if any
    1.67 +//            Throwable ourCause = getCause();
    1.68 +////            if (ourCause != null)
    1.69 +////                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
    1.70 +//        }
    1.71 +//    }
    1.72 +//
    1.73 +//    /**
    1.74 +//     * Print our stack trace as an enclosed exception for the specified
    1.75 +//     * stack trace.
    1.76 +//     */
    1.77 +//    private void printEnclosedStackTrace(PrintStreamOrWriter s,
    1.78 +//                                         StackTraceElement[] enclosingTrace,
    1.79 +//                                         String caption,
    1.80 +//                                         String prefix,
    1.81 +//                                         Object dejaVu) {
    1.82 +//        assert Thread.holdsLock(s.lock());
    1.83 +//        {
    1.84 +//            // Compute number of frames in common between this and enclosing trace
    1.85 +//            StackTraceElement[] trace = getOurStackTrace();
    1.86 +//            int m = trace.length - 1;
    1.87 +//            int n = enclosingTrace.length - 1;
    1.88 +//            while (m >= 0 && n >=0 && trace[m].equals(enclosingTrace[n])) {
    1.89 +//                m--; n--;
    1.90 +//            }
    1.91 +//            int framesInCommon = trace.length - 1 - m;
    1.92 +//
    1.93 +//            // Print our stack trace
    1.94 +//            s.println(prefix + caption + this);
    1.95 +//            for (int i = 0; i <= m; i++)
    1.96 +//                s.println(prefix + "\tat " + trace[i]);
    1.97 +//            if (framesInCommon != 0)
    1.98 +//                s.println(prefix + "\t... " + framesInCommon + " more");
    1.99 +//
   1.100 +//            // Print suppressed exceptions, if any
   1.101  //            for (Throwable se : getSuppressed())
   1.102 -//                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
   1.103 -
   1.104 -            // Print cause, if any
   1.105 -            Throwable ourCause = getCause();
   1.106 +//                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION,
   1.107 +//                                           prefix +"\t", dejaVu);
   1.108 +//
   1.109 +//            // Print cause, if any
   1.110 +//            Throwable ourCause = getCause();
   1.111  //            if (ourCause != null)
   1.112 -//                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
   1.113 -        }
   1.114 -    }
   1.115 -
   1.116 -    /**
   1.117 -     * Print our stack trace as an enclosed exception for the specified
   1.118 -     * stack trace.
   1.119 -     */
   1.120 -    private void printEnclosedStackTrace(PrintStreamOrWriter s,
   1.121 -                                         StackTraceElement[] enclosingTrace,
   1.122 -                                         String caption,
   1.123 -                                         String prefix,
   1.124 -                                         Object dejaVu) {
   1.125 -        assert Thread.holdsLock(s.lock());
   1.126 -        {
   1.127 -            // Compute number of frames in common between this and enclosing trace
   1.128 -            StackTraceElement[] trace = getOurStackTrace();
   1.129 -            int m = trace.length - 1;
   1.130 -            int n = enclosingTrace.length - 1;
   1.131 -            while (m >= 0 && n >=0 && trace[m].equals(enclosingTrace[n])) {
   1.132 -                m--; n--;
   1.133 -            }
   1.134 -            int framesInCommon = trace.length - 1 - m;
   1.135 -
   1.136 -            // Print our stack trace
   1.137 -            s.println(prefix + caption + this);
   1.138 -            for (int i = 0; i <= m; i++)
   1.139 -                s.println(prefix + "\tat " + trace[i]);
   1.140 -            if (framesInCommon != 0)
   1.141 -                s.println(prefix + "\t... " + framesInCommon + " more");
   1.142 -
   1.143 -            // Print suppressed exceptions, if any
   1.144 -            for (Throwable se : getSuppressed())
   1.145 -                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION,
   1.146 -                                           prefix +"\t", dejaVu);
   1.147 -
   1.148 -            // Print cause, if any
   1.149 -            Throwable ourCause = getCause();
   1.150 -            if (ourCause != null)
   1.151 -                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, prefix, dejaVu);
   1.152 -        }
   1.153 -    }
   1.154 -
   1.155 -    /**
   1.156 -     * Prints this throwable and its backtrace to the specified
   1.157 -     * print writer.
   1.158 -     *
   1.159 -     * @param s {@code PrintWriter} to use for output
   1.160 -     * @since   JDK1.1
   1.161 -     */
   1.162 -    public void printStackTrace(PrintWriter s) {
   1.163 -        printStackTrace(new WrappedPrintWriter(s));
   1.164 -    }
   1.165 -
   1.166 -    /**
   1.167 -     * Wrapper class for PrintStream and PrintWriter to enable a single
   1.168 -     * implementation of printStackTrace.
   1.169 -     */
   1.170 -    private abstract static class PrintStreamOrWriter {
   1.171 -        /** Returns the object to be locked when using this StreamOrWriter */
   1.172 -        abstract Object lock();
   1.173 -
   1.174 -        /** Prints the specified string as a line on this StreamOrWriter */
   1.175 -        abstract void println(Object o);
   1.176 -    }
   1.177 -
   1.178 -    private static class WrappedPrintStream extends PrintStreamOrWriter {
   1.179 -        private final PrintStream printStream;
   1.180 -
   1.181 -        WrappedPrintStream(PrintStream printStream) {
   1.182 -            this.printStream = printStream;
   1.183 -        }
   1.184 -
   1.185 -        Object lock() {
   1.186 -            return printStream;
   1.187 -        }
   1.188 -
   1.189 -        void println(Object o) {
   1.190 -            printStream.println(o);
   1.191 -        }
   1.192 -    }
   1.193 -
   1.194 -    private static class WrappedPrintWriter extends PrintStreamOrWriter {
   1.195 -        private final PrintWriter printWriter;
   1.196 -
   1.197 -        WrappedPrintWriter(PrintWriter printWriter) {
   1.198 -            this.printWriter = printWriter;
   1.199 -        }
   1.200 -
   1.201 -        Object lock() {
   1.202 -            return printWriter;
   1.203 -        }
   1.204 -
   1.205 -        void println(Object o) {
   1.206 -            printWriter.println(o);
   1.207 -        }
   1.208 -    }
   1.209 +//                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, prefix, dejaVu);
   1.210 +//        }
   1.211 +//    }
   1.212 +//
   1.213 +//    /**
   1.214 +//     * Prints this throwable and its backtrace to the specified
   1.215 +//     * print writer.
   1.216 +//     *
   1.217 +//     * @param s {@code PrintWriter} to use for output
   1.218 +//     * @since   JDK1.1
   1.219 +//     */
   1.220 +//    public void printStackTrace(PrintWriter s) {
   1.221 +//        printStackTrace(new WrappedPrintWriter(s));
   1.222 +//    }
   1.223 +//
   1.224 +//    /**
   1.225 +//     * Wrapper class for PrintStream and PrintWriter to enable a single
   1.226 +//     * implementation of printStackTrace.
   1.227 +//     */
   1.228 +//    private abstract static class PrintStreamOrWriter {
   1.229 +//        /** Returns the object to be locked when using this StreamOrWriter */
   1.230 +//        abstract Object lock();
   1.231 +//
   1.232 +//        /** Prints the specified string as a line on this StreamOrWriter */
   1.233 +//        abstract void println(Object o);
   1.234 +//    }
   1.235 +//
   1.236 +//    private static class WrappedPrintStream extends PrintStreamOrWriter {
   1.237 +//        private final PrintStream printStream;
   1.238 +//
   1.239 +//        WrappedPrintStream(PrintStream printStream) {
   1.240 +//            this.printStream = printStream;
   1.241 +//        }
   1.242 +//
   1.243 +//        Object lock() {
   1.244 +//            return printStream;
   1.245 +//        }
   1.246 +//
   1.247 +//        void println(Object o) {
   1.248 +//            printStream.println(o);
   1.249 +//        }
   1.250 +//    }
   1.251 +//
   1.252 +//    private static class WrappedPrintWriter extends PrintStreamOrWriter {
   1.253 +//        private final PrintWriter printWriter;
   1.254 +//
   1.255 +//        WrappedPrintWriter(PrintWriter printWriter) {
   1.256 +//            this.printWriter = printWriter;
   1.257 +//        }
   1.258 +//
   1.259 +//        Object lock() {
   1.260 +//            return printWriter;
   1.261 +//        }
   1.262 +//
   1.263 +//        void println(Object o) {
   1.264 +//            printWriter.println(o);
   1.265 +//        }
   1.266 +//    }
   1.267  
   1.268      /**
   1.269       * Fills in the execution stack trace. This method records within this
   1.270 @@ -966,23 +966,23 @@
   1.271       * form as a one-element array whose element is equal to {@code
   1.272       * new StackTraceElement("", "", null, Integer.MIN_VALUE)}.
   1.273       */
   1.274 -    private synchronized void writeObject(ObjectOutputStream s)
   1.275 -        throws IOException {
   1.276 -        // Ensure that the stackTrace field is initialized to a
   1.277 -        // non-null value, if appropriate.  As of JDK 7, a null stack
   1.278 -        // trace field is a valid value indicating the stack trace
   1.279 -        // should not be set.
   1.280 -        getOurStackTrace();
   1.281 -
   1.282 -        StackTraceElement[] oldStackTrace = stackTrace;
   1.283 -        try {
   1.284 -            if (stackTrace == null)
   1.285 -                stackTrace = SentinelHolder.STACK_TRACE_SENTINEL;
   1.286 -            s.defaultWriteObject();
   1.287 -        } finally {
   1.288 -            stackTrace = oldStackTrace;
   1.289 -        }
   1.290 -    }
   1.291 +//    private synchronized void writeObject(ObjectOutputStream s)
   1.292 +//        throws IOException {
   1.293 +//        // Ensure that the stackTrace field is initialized to a
   1.294 +//        // non-null value, if appropriate.  As of JDK 7, a null stack
   1.295 +//        // trace field is a valid value indicating the stack trace
   1.296 +//        // should not be set.
   1.297 +//        getOurStackTrace();
   1.298 +//
   1.299 +//        StackTraceElement[] oldStackTrace = stackTrace;
   1.300 +//        try {
   1.301 +//            if (stackTrace == null)
   1.302 +//                stackTrace = SentinelHolder.STACK_TRACE_SENTINEL;
   1.303 +//            s.defaultWriteObject();
   1.304 +//        } finally {
   1.305 +//            stackTrace = oldStackTrace;
   1.306 +//        }
   1.307 +//    }
   1.308  
   1.309      /**
   1.310       * Appends the specified exception to the exceptions that were