mcnamara 2004/08/17 09:17:43
Modified: java/src/org/apache/xml/dtm DTMException.java
Log:
Fix for printStackTrace when using JDK 1.4
Revision Changes Path
1.8 +53 -39 xml-xalan/java/src/org/apache/xml/dtm/DTMException.java
Index: DTMException.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/DTMException.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DTMException.java 16 Feb 2004 23:03:44 -0000 1.7
+++ DTMException.java 17 Aug 2004 16:17:42 -0000 1.8
@@ -33,6 +33,7 @@
* in the DTM module.
*/
public class DTMException extends RuntimeException {
+ static final long serialVersionUID = -775576419181334734L;
/** Field locator specifies where the error occured.
* @serial */
@@ -318,49 +319,62 @@
super.printStackTrace(s);
} catch (Throwable e) {}
- Throwable exception = getException();
-
- for (int i = 0; (i < 10) && (null != exception); i++) {
- s.println("---------");
-
- try {
- if (exception instanceof DTMException) {
- String locInfo =
- ((DTMException) exception)
- .getLocationAsString();
-
- if (null != locInfo) {
- s.println(locInfo);
+ boolean isJdk14OrHigher = false;
+ try {
+ Throwable.class.getMethod("getCause",null);
+ isJdk14OrHigher = true;
+ } catch (NoSuchMethodException nsme) {
+ // do nothing
+ }
+
+ // 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();
+
+ for (int i = 0; (i < 10) && (null != exception); i++) {
+ s.println("---------");
+
+ try {
+ if (exception instanceof DTMException) {
+ String locInfo =
+ ((DTMException) exception)
+ .getLocationAsString();
+
+ 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",
- null);
-
- if (null != meth) {
- Throwable prev = exception;
-
- exception = (Throwable) meth.invoke(exception, null);
-
- if (prev == exception) {
- break;
+
+ try {
+ Method meth =
+ ((Object)
exception).getClass().getMethod("getException",
+ null);
+
+ if (null != meth) {
+ Throwable prev = exception;
+
+ exception = (Throwable) meth.invoke(exception, null);
+
+ 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;
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]