DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=29893>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=29893

DTMManagerDefault.getDTM() incorrectly returns null

           Summary: DTMManagerDefault.getDTM() incorrectly returns null
           Product: XalanJ2
           Version: 2.6
          Platform: All
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: org.apache.xml.dtm
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


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)
  {
    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)
  {
      // 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);
      }
  }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to