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

DTMManagerDefault.getDTM() incorrectly returns null

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.6
    • None
    • DTM
    • Security Level: No security risk; visible to anyone (Ordinary problems in Xalan projects. Anybody can view the issue.)
    • None
    • Operating System: Other
      Platform: All
    • 29893

    Description

      The following suggested fix for
      org.apache.xml.dtm.ref.XTMManagerDefault.getDTM()
      relates to Bug 22217
      NullPointerException in TransformerImpl.run() when reusing XMLFilter object
      http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22217

      =======================================================================
      In the interface file we read:

      /*

      • $Id: DTMManager.java,v 1.18 2004/02/23 10:29:36 aruny Exp $
        */
        package org.apache.xml.dtm;
        ....
        /**
      • Get the instance of DTM that "owns" a node handle.
        *
      • @param nodeHandle the nodeHandle.
        *
      • @return a non-null DTM reference.
        */
        public abstract DTM getDTM(int nodeHandle);
        ======================================================================
        Note in particular that the return is non-null.

      In the implementation we read:
      ======================================================================

      /*

      • $Id: DTMManagerDefault.java,v 1.51 2004/02/16 23:06:11 minchau Exp $
        */
        package org.apache.xml.dtm.ref;
        ....
        /**
      • Return the DTM object containing a representation of this node.
        *
      • @param nodeHandle DTM Handle indicating which node to retrieve
        *
      • @return a reference to the DTM object containing this node.
        */
        synchronized public DTM getDTM(int nodeHandle)
        Unknown macro: { try { // Performance critical function. return m_dtms[nodeHandle >>> IDENT_DTM_NODE_BITS]; } catch(java.lang.ArrayIndexOutOfBoundsException e) { if(nodeHandle==DTM.NULL) return null; // Accept as a special case. else throw e; // Programming error; want to know about it. } }

        ====================================================================
        In addition to the "special case", the array m_dtms can have "null"
        values that are returned, contrary to the interface documentation.

      Callers of getDTM() use the return value without checking for null,
      for example
      =======================================================================
      /*

      • $Id: TransformerImpl.java,v 1.158 2004/02/23 21:33:14 igorh Exp $
        */
        package org.apache.xalan.transformer;
        ...
        public boolean applyTemplateToNode(ElemTemplateElement xslInstruction, //
        xsl:apply-templates or xsl:for-each
        ElemTemplate template, int child)
        throws TransformerException
        {

      DTM dtm = m_xcontext.getDTM(child);
      short nodeType = dtm.getNodeType(child); <<<<<<<<<<<< NPE!!

      boolean isDefaultTextRule = false;
      boolean isApplyImports = false;
      ...
      =================================================================
      In my opinion getDTM() should be thus:
      ==================================================================
      /**

      • Return the DTM object containing a representation of this node.
        *
      • @param nodeHandle DTM Handle indicating which node to retrieve
        *
      • @return a reference to the DTM object containing this node.
        */
        synchronized public DTM getDTM(int nodeHandle)
        Unknown macro: { // Performance critical function. DTM dtm = m_dtms[nodeHandle >>> IDENT_DTM_NODE_BITS]; if (dtm != null) { return dtm; } else { throw new TransformerException(this.getClass().getName() +" Document Table contains null pointer for nodeHandle="+nodeHandle); } }

      Attachments

        Activity

          People

            Unassigned Unassigned
            johnjbarton@johnjbarton.com John J. Barton
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: