You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-cvs@xml.apache.org by mk...@apache.org on 2005/06/14 21:13:41 UTC

cvs commit: xml-commons/java/external/src/javax/xml/transform TransformerException.java

mkwan       2005/06/14 12:13:40

  Modified:    java/external/src/javax/xml/transform
                        TransformerException.java
  Log:
  Migrate a bug fix for printStackTrace which was done before the JAXP 1.3 integration
  back to the head.
  
  Revision  Changes    Path
  1.6       +44 -31    xml-commons/java/external/src/javax/xml/transform/TransformerException.java
  
  Index: TransformerException.java
  ===================================================================
  RCS file: /home/cvs/xml-commons/java/external/src/javax/xml/transform/TransformerException.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TransformerException.java	8 Apr 2005 10:39:13 -0000	1.5
  +++ TransformerException.java	14 Jun 2005 19:13:40 -0000	1.6
  @@ -312,49 +312,62 @@
               super.printStackTrace(s);
           } catch (Throwable e) {}
   
  -        Throwable exception = getException();
  -
  -        for (int i = 0; (i < 10) && (null != exception); i++) {
  -            s.println("---------");
  +        boolean isJdk14OrHigher = false;
  +        try {
  +        	Throwable.class.getMethod("getCause",null);
  +        	isJdk14OrHigher = true;
  +        } catch (NoSuchMethodException nsme) {
  +        	// do nothing
  +        }
   
  -            try {
  -                if (exception instanceof TransformerException) {
  -                    String locInfo =
  -                        ((TransformerException) exception)
  +        // 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 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