Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-767

TransformerException does not include SAXParseException location info

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Resolution: Fixed
    • 2.1.0
    • None
    • JAXP
    • None
    • Operating System: Linux
      Platform: PC
    • 5872

    Description

      When creating a Transformer from TransformerFactory.newInstance() by passing a
      StreamSource of XSLT, a TransformerException is thrown, but does not include any
      location information.

      By exploring the TransformerException using this bit of code, I saw there was a
      SAXParseException that contained location information:

      boolean known = true;
      while (known && (t != null)) {
      if (t instanceof TransformerException)

      { known = true; log4j.debug("Analysing known exception: " + t.getClass().getName()); log4j.debug("getLocationAsString(): " + ((TransformerException) t).getLocationAsString() + ""); t = ((TransformerException) t).getCause(); }

      else if (t instanceof org.xml.sax.SAXParseException)

      { known = true; log4j.debug("Analysing known exception: " + t.getClass().getName()); int col = ((org.xml.sax.SAXParseException) t).getColumnNumber(); int line = ((org.xml.sax.SAXParseException) t).getLineNumber(); log4j.debug("Location: Col=" + col + ", line=" + line); t = ((org.xml.sax.SAXParseException) t).getException(); }

      else

      { log4j.debug("Unknown cause: " + t.getClass().getName()); known = false; }

      }

      Note: If you don't use log4j, replace "log4j.debug" by "System.out.println", for
      example.

      The result of this exploration gives:

      Analysing known exception: javax.xml.transform.TransformerConfigurationException
      getLocationAsString(): null
      Analysing known exception: javax.xml.transform.TransformerConfigurationException
      getLocationAsString(): null
      Analysing known exception: javax.xml.transform.TransformerException
      getLocationAsString(): null
      Analysing known exception: org.xml.sax.SAXParseException
      Location: Col=76, line=85

      Attachments

        Activity

          People

            mmidy@apache.org Myriam Midy
            nicolas@marchildon.net Nicolas Marchildon
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: