emul/src/main/java/java/lang/Throwable.java
branchemul
changeset 61 4b334950499d
parent 51 506ef276a0db
child 65 f99a92839285
     1.1 --- a/emul/src/main/java/java/lang/Throwable.java	Sat Sep 29 06:34:18 2012 +0200
     1.2 +++ b/emul/src/main/java/java/lang/Throwable.java	Sat Sep 29 08:13:32 2012 +0200
     1.3 @@ -25,7 +25,6 @@
     1.4  
     1.5  package java.lang;
     1.6  import  java.io.*;
     1.7 -import  java.util.*;
     1.8  
     1.9  /**
    1.10   * The {@code Throwable} class is the superclass of all errors and
    1.11 @@ -211,8 +210,9 @@
    1.12  
    1.13      // Setting this static field introduces an acceptable
    1.14      // initialization dependency on a few java.util classes.
    1.15 -    private static final List<Throwable> SUPPRESSED_SENTINEL =
    1.16 -        Collections.unmodifiableList(new ArrayList<Throwable>(0));
    1.17 +// I don't think this dependency is acceptable
    1.18 +//    private static final List<Throwable> SUPPRESSED_SENTINEL =
    1.19 +//        Collections.unmodifiableList(new ArrayList<Throwable>(0));
    1.20  
    1.21      /**
    1.22       * The list of suppressed exceptions, as returned by {@link
    1.23 @@ -224,7 +224,7 @@
    1.24       * @serial
    1.25       * @since 1.7
    1.26       */
    1.27 -    private List<Throwable> suppressedExceptions = SUPPRESSED_SENTINEL;
    1.28 +//    private List<Throwable> suppressedExceptions = SUPPRESSED_SENTINEL;
    1.29  
    1.30      /** Message for trying to suppress a null exception. */
    1.31      private static final String NULL_CAUSE_MESSAGE = "Cannot suppress a null exception.";
    1.32 @@ -363,8 +363,8 @@
    1.33          }
    1.34          detailMessage = message;
    1.35          this.cause = cause;
    1.36 -        if (!enableSuppression)
    1.37 -            suppressedExceptions = null;
    1.38 +//        if (!enableSuppression)
    1.39 +//            suppressedExceptions = null;
    1.40      }
    1.41  
    1.42      /**
    1.43 @@ -645,9 +645,9 @@
    1.44      private void printStackTrace(PrintStreamOrWriter s) {
    1.45          // Guard against malicious overrides of Throwable.equals by
    1.46          // using a Set with identity equality semantics.
    1.47 -        Set<Throwable> dejaVu =
    1.48 -            Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
    1.49 -        dejaVu.add(this);
    1.50 +//        Set<Throwable> dejaVu =
    1.51 +//            Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
    1.52 +//        dejaVu.add(this);
    1.53  
    1.54          synchronized (s.lock()) {
    1.55              // Print our stack trace
    1.56 @@ -657,13 +657,13 @@
    1.57                  s.println("\tat " + traceElement);
    1.58  
    1.59              // Print suppressed exceptions, if any
    1.60 -            for (Throwable se : getSuppressed())
    1.61 -                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
    1.62 +//            for (Throwable se : getSuppressed())
    1.63 +//                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
    1.64  
    1.65              // Print cause, if any
    1.66              Throwable ourCause = getCause();
    1.67 -            if (ourCause != null)
    1.68 -                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
    1.69 +//            if (ourCause != null)
    1.70 +//                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
    1.71          }
    1.72      }
    1.73  
    1.74 @@ -675,12 +675,9 @@
    1.75                                           StackTraceElement[] enclosingTrace,
    1.76                                           String caption,
    1.77                                           String prefix,
    1.78 -                                         Set<Throwable> dejaVu) {
    1.79 +                                         Object dejaVu) {
    1.80          assert Thread.holdsLock(s.lock());
    1.81 -        if (dejaVu.contains(this)) {
    1.82 -            s.println("\t[CIRCULAR REFERENCE:" + this + "]");
    1.83 -        } else {
    1.84 -            dejaVu.add(this);
    1.85 +        {
    1.86              // Compute number of frames in common between this and enclosing trace
    1.87              StackTraceElement[] trace = getOurStackTrace();
    1.88              int m = trace.length - 1;
    1.89 @@ -911,25 +908,25 @@
    1.90      private void readObject(ObjectInputStream s)
    1.91          throws IOException, ClassNotFoundException {
    1.92          s.defaultReadObject();     // read in all fields
    1.93 -        if (suppressedExceptions != null) {
    1.94 -            List<Throwable> suppressed = null;
    1.95 -            if (suppressedExceptions.isEmpty()) {
    1.96 -                // Use the sentinel for a zero-length list
    1.97 -                suppressed = SUPPRESSED_SENTINEL;
    1.98 -            } else { // Copy Throwables to new list
    1.99 -                suppressed = new ArrayList<Throwable>(1);
   1.100 -                for (Throwable t : suppressedExceptions) {
   1.101 -                    // Enforce constraints on suppressed exceptions in
   1.102 -                    // case of corrupt or malicious stream.
   1.103 -                    if (t == null)
   1.104 -                        throw new NullPointerException(NULL_CAUSE_MESSAGE);
   1.105 -                    if (t == this)
   1.106 -                        throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
   1.107 -                    suppressed.add(t);
   1.108 -                }
   1.109 -            }
   1.110 -            suppressedExceptions = suppressed;
   1.111 -        } // else a null suppressedExceptions field remains null
   1.112 +//        if (suppressedExceptions != null) {
   1.113 +//            List<Throwable> suppressed = null;
   1.114 +//            if (suppressedExceptions.isEmpty()) {
   1.115 +//                // Use the sentinel for a zero-length list
   1.116 +//                suppressed = SUPPRESSED_SENTINEL;
   1.117 +//            } else { // Copy Throwables to new list
   1.118 +//                suppressed = new ArrayList<Throwable>(1);
   1.119 +//                for (Throwable t : suppressedExceptions) {
   1.120 +//                    // Enforce constraints on suppressed exceptions in
   1.121 +//                    // case of corrupt or malicious stream.
   1.122 +//                    if (t == null)
   1.123 +//                        throw new NullPointerException(NULL_CAUSE_MESSAGE);
   1.124 +//                    if (t == this)
   1.125 +//                        throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
   1.126 +//                    suppressed.add(t);
   1.127 +//                }
   1.128 +//            }
   1.129 +//            suppressedExceptions = suppressed;
   1.130 +//        } // else a null suppressedExceptions field remains null
   1.131  
   1.132          /*
   1.133           * For zero-length stack traces, use a clone of
   1.134 @@ -1044,13 +1041,13 @@
   1.135          if (exception == null)
   1.136              throw new NullPointerException(NULL_CAUSE_MESSAGE);
   1.137  
   1.138 -        if (suppressedExceptions == null) // Suppressed exceptions not recorded
   1.139 -            return;
   1.140 -
   1.141 -        if (suppressedExceptions == SUPPRESSED_SENTINEL)
   1.142 -            suppressedExceptions = new ArrayList<Throwable>(1);
   1.143 -
   1.144 -        suppressedExceptions.add(exception);
   1.145 +//        if (suppressedExceptions == null) // Suppressed exceptions not recorded
   1.146 +//            return;
   1.147 +//
   1.148 +//        if (suppressedExceptions == SUPPRESSED_SENTINEL)
   1.149 +//            suppressedExceptions = new ArrayList<Throwable>(1);
   1.150 +//
   1.151 +//        suppressedExceptions.add(exception);
   1.152      }
   1.153  
   1.154      private static final Throwable[] EMPTY_THROWABLE_ARRAY = new Throwable[0];
   1.155 @@ -1071,10 +1068,11 @@
   1.156       * @since 1.7
   1.157       */
   1.158      public final synchronized Throwable[] getSuppressed() {
   1.159 -        if (suppressedExceptions == SUPPRESSED_SENTINEL ||
   1.160 -            suppressedExceptions == null)
   1.161 -            return EMPTY_THROWABLE_ARRAY;
   1.162 -        else
   1.163 -            return suppressedExceptions.toArray(EMPTY_THROWABLE_ARRAY);
   1.164 +        return new Throwable[0];
   1.165 +//        if (suppressedExceptions == SUPPRESSED_SENTINEL ||
   1.166 +//            suppressedExceptions == null)
   1.167 +//            return EMPTY_THROWABLE_ARRAY;
   1.168 +//        else
   1.169 +//            return suppressedExceptions.toArray(EMPTY_THROWABLE_ARRAY);
   1.170      }
   1.171  }