diff --git a/java/external/src/javax/xml/transform/TransformerException.java b/java/external/src/javax/xml/transform/TransformerException.java index ed24cfb..f58b8df 100644 --- a/java/external/src/javax/xml/transform/TransformerException.java +++ b/java/external/src/javax/xml/transform/TransformerException.java @@ -312,49 +312,62 @@ public class TransformerException extends Exception { super.printStackTrace(s); } catch (Throwable e) {} - Throwable exception = getException(); + boolean isJdk14OrHigher = false; + try { + Throwable.class.getMethod("getCause",null); + isJdk14OrHigher = true; + } catch (NoSuchMethodException nsme) { + // do nothing + } - for (int i = 0; (i < 10) && (null != exception); i++) { - s.println("---------"); + // The printStackTrace method of the Throwable class in jdk 1.4 + // and higher will include the cause when printing the backtrace. + // The following code is only required when using jdk 1.3 or lower + if (!isJdk14OrHigher) { + Throwable exception = getException(); - try { - if (exception instanceof TransformerException) { - String locInfo = - ((TransformerException) exception) + for (int i = 0; (i < 10) && (null != exception); i++) { + s.println("---------"); + + try { + if (exception instanceof TransformerException) { + String locInfo = + ((TransformerException) exception) .getLocationAsString(); - if (null != locInfo) { - s.println(locInfo); + if (null != locInfo) { + s.println(locInfo); + } } + + exception.printStackTrace(s); + } catch (Throwable e) { + s.println("Could not print stack trace..."); } - exception.printStackTrace(s); - } catch (Throwable e) { - s.println("Could not print stack trace..."); - } - - try { - Method meth = - ((Object) exception).getClass().getMethod("getException", + try { + Method meth = + ((Object) exception).getClass().getMethod("getException", null); - if (null != meth) { - Throwable prev = exception; + if (null != meth) { + Throwable prev = exception; - exception = (Throwable) meth.invoke(exception, null); + exception = (Throwable) meth.invoke(exception, null); - if (prev == exception) { - break; + if (prev == exception) { + break; + } + } else { + exception = null; } - } else { + } catch (InvocationTargetException ite) { + exception = null; + } catch (IllegalAccessException iae) { + exception = null; + } catch (NoSuchMethodException nsme) { exception = null; } - } catch (InvocationTargetException ite) { - exception = null; - } catch (IllegalAccessException iae) { - exception = null; - } catch (NoSuchMethodException nsme) { - exception = null; } } // insure output is written