jaxp/src/java.xml/share/classes/javax/xml/transform/TransformerException.java
changeset 31497 4a6b2e733c0d
parent 25868 686eef1e7a79
child 46005 49e2e73f90f6
equal deleted inserted replaced
31302:f66c18528472 31497:4a6b2e733c0d
   108      *         {@link #TransformerException(String,Throwable)}, or this method has already
   108      *         {@link #TransformerException(String,Throwable)}, or this method has already
   109      *         been called on this throwable.
   109      *         been called on this throwable.
   110      */
   110      */
   111     public synchronized Throwable initCause(Throwable cause) {
   111     public synchronized Throwable initCause(Throwable cause) {
   112 
   112 
       
   113         // TransformerException doesn't set its cause (probably
       
   114         // because it predates initCause()) - and we may not want
       
   115         // to change this since Exceptions are serializable...
       
   116         // But this also leads to the broken code in printStackTrace
       
   117         // below...
       
   118 
   113         if (this.containedException != null) {
   119         if (this.containedException != null) {
   114             throw new IllegalStateException("Can't overwrite cause");
   120             throw new IllegalStateException("Can't overwrite cause");
   115         }
   121         }
   116 
   122 
   117         if (cause == this) {
   123         if (cause == this) {
   310         if (s == null) {
   316         if (s == null) {
   311             s = new java.io.PrintWriter(System.err, true);
   317             s = new java.io.PrintWriter(System.err, true);
   312         }
   318         }
   313 
   319 
   314         try {
   320         try {
   315             String locInfo = getLocationAsString();
       
   316 
       
   317             if (null != locInfo) {
       
   318                 s.println(locInfo);
       
   319             }
       
   320 
       
   321             super.printStackTrace(s);
       
   322         } catch (Throwable e) {}
       
   323 
       
   324         Throwable exception = getException();
       
   325 
       
   326         for (int i = 0; (i < 10) && (null != exception); i++) {
       
   327             s.println("---------");
       
   328 
       
   329             try {
   321             try {
   330                 if (exception instanceof TransformerException) {
   322                 String locInfo = getLocationAsString();
   331                     String locInfo =
   323 
   332                         ((TransformerException) exception)
   324                 if (null != locInfo) {
   333                             .getLocationAsString();
   325                     s.println(locInfo);
   334 
   326                 }
   335                     if (null != locInfo) {
   327 
   336                         s.println(locInfo);
   328                 super.printStackTrace(s);
       
   329             } catch (Throwable e) {}
       
   330 
       
   331             Throwable exception = getException();
       
   332 
       
   333             for (int i = 0; (i < 10) && (null != exception); i++) {
       
   334                 s.println("---------");
       
   335 
       
   336                 try {
       
   337                     exception.printStackTrace(s);
       
   338                     // if exception is a TransformerException it will print
       
   339                     // its contained exception, so we don't need to redo it here,
       
   340                     // and we can exit the loop now.
       
   341                     if (exception instanceof TransformerException) break;
       
   342                 } catch (Throwable e) {
       
   343                     s.println("Could not print stack trace...");
       
   344                 }
       
   345 
       
   346                 try {
       
   347                     // Is this still needed?
       
   348                     Method meth = exception.getClass().getMethod("getException");
       
   349 
       
   350                     if (null != meth) {
       
   351                         Throwable prev = exception;
       
   352 
       
   353                         exception = (Throwable) meth.invoke(exception, (Object[]) null);
       
   354 
       
   355                         if (prev == exception) {
       
   356                             break;
       
   357                         }
       
   358                     } else {
       
   359                         exception = null;
   337                     }
   360                     }
   338                 }
   361                 } catch (InvocationTargetException ite) {
   339 
   362                     exception = null;
   340                 exception.printStackTrace(s);
   363                 } catch (IllegalAccessException iae) {
   341             } catch (Throwable e) {
   364                     exception = null;
   342                 s.println("Could not print stack trace...");
   365                 } catch (NoSuchMethodException nsme) {
   343             }
       
   344 
       
   345             try {
       
   346                 Method meth =
       
   347                     ((Object) exception).getClass().getMethod("getException",
       
   348                         (Class[]) null);
       
   349 
       
   350                 if (null != meth) {
       
   351                     Throwable prev = exception;
       
   352 
       
   353                     exception = (Throwable) meth.invoke(exception, (Object[]) null);
       
   354 
       
   355                     if (prev == exception) {
       
   356                         break;
       
   357                     }
       
   358                 } else {
       
   359                     exception = null;
   366                     exception = null;
   360                 }
   367                 }
   361             } catch (InvocationTargetException ite) {
   368             }
   362                 exception = null;
   369         } finally {
   363             } catch (IllegalAccessException iae) {
   370             // ensure output is written
   364                 exception = null;
   371             s.flush();
   365             } catch (NoSuchMethodException nsme) {
   372         }
   366                 exception = null;
       
   367             }
       
   368         }
       
   369         // insure output is written
       
   370         s.flush();
       
   371     }
   373     }
   372 }
   374 }