You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mc...@apache.org on 2004/08/17 18:18:27 UTC

cvs commit: xml-xalan/java/src/org/apache/xpath XPathException.java

mcnamara    2004/08/17 09:18:27

  Modified:    java/src/org/apache/xpath XPathException.java
  Log:
  Fix for printStackTrace when using JDK 1.4
  
  Revision  Changes    Path
  1.13      +42 -26    xml-xalan/java/src/org/apache/xpath/XPathException.java
  
  Index: XPathException.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/XPathException.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- XPathException.java	17 Feb 2004 04:30:02 -0000	1.12
  +++ XPathException.java	17 Aug 2004 16:18:27 -0000	1.13
  @@ -33,6 +33,7 @@
    */
   public class XPathException extends TransformerException
   {
  +    static final long serialVersionUID = 4263549717619045963L;
   
     /** The home of the expression that caused the error.
      *  @serial  */
  @@ -254,45 +255,60 @@
   
       if (s == null)
         s = new java.io.PrintWriter(System.err);
  -
  +        
       try
       {
         super.printStackTrace(s);
       }
       catch (Exception e){}
  +    
  +    
  +    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 = m_exception;
   
  -    Throwable exception = m_exception;
  +      for (int i = 0; (i < 10) && (null != exception); i++)
  +      {
  +        s.println("---------");
   
  -    for (int i = 0; (i < 10) && (null != exception); i++)
  -    {
  -      s.println("---------");
  +        try
  +        {
  +          exception.printStackTrace(s);
  +        }
  +        catch (Exception e)
  +        {
  +          s.println("Could not print stack trace...");
  +        }
   
  -      try
  -      {
  -        exception.printStackTrace(s);
  -      }
  -      catch (Exception e)
  -      {
  -        s.println("Could not print stack trace...");
  -      }
  +        if (exception instanceof TransformerException)
  +        {
  +          TransformerException se = (TransformerException) exception;
  +          Throwable prev = exception;
   
  -      if (exception instanceof TransformerException)
  -      {
  -        TransformerException se = (TransformerException) exception;
  -        Throwable prev = exception;
  +          exception = se.getException();
   
  -        exception = se.getException();
  +          if (prev == exception)
  +          {
  +            exception = null;
   
  -        if (prev == exception)
  +            break;
  +          }
  +        }
  +        else
           {
             exception = null;
  -
  -          break;
           }
  -      }
  -      else
  -      {
  -        exception = null;
         }
       }
     }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org