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

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5496

Attlist.getValue and getIndex do not work

           Summary: Attlist.getValue and getIndex do not work
           Product: XalanJ2
           Version: 2.2.x
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: org.apache.xml.utils
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


This problem with getValue has been looked at by Joe Kesselmann who wrote:
======Joe's mail=====================================================
Looking at getValue: It's miscoded. It assumes that the matching attribute
will be found and immediately tries to convert it to a string, rather than
stopping to check whether the match might have failed and returned null.
     return ((Attr) m_attrs.getNamedItem(localName)).getValue();

Actually, that's _badly_ miscoded; it also isn't using the namespace-aware
call, which is why the search failed in the first place. Changing it to
     Node a=m_attrs.getNamedItemNS(uri,localName);
     return (a==null) ? null : a.getNodeValue();
cures the problem. This also avoids the typecast overhead, which should
save us a cycle or two.

Definite bug, trivial fix. I'll check it in.
=======================end Joe's mail=======================

=======================how to reproduce both problems============
To reproduce the problem: run the main() function in the class JaxpTest2 
passing as an argument the name of a file which contains the following text:

<?xml version="1.0" encoding="UTF-8"?>
<deleted xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
    xmlns:enc="http://www.w3.org/2001/06/soap-encoding"; 
xsi:type="B1">0</deleted>

The JaxpTest2 tries to access the attributes of the root via a small handler 
called TestHandler. The call to getIndex() which expects to retrieve the local 
name 'type' actually returns the attribute with local name 'enc'. The call to 
getValue() causes a NullPointer exception:
java.lang.NullPointerException
        java.lang.String org.apache.xml.utils.AttList.getValue
(java.lang.String, java.lang.String)
        void jaxp.test.TestHandler.startElement(java.lang.String, 
java.lang.String, java.lang.String, org.xml.sax.Attributes)
        void org.apache.xalan.transformer.TransformerIdentityImpl.startElement
(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
        void org.apache.xml.utils.TreeWalker.startNode(org.w3c.dom.Node)
        void org.apache.xml.utils.TreeWalker.traverse(org.w3c.dom.Node)
        void org.apache.xalan.transformer.TransformerIdentityImpl.transform
(javax.xml.transform.Source, javax.xml.transform.Result)
        void jaxp.test.JaxpTest2.main(java.lang.String[])
================================JaxpTest2=====================

// Copyright (c) 2001 Brooks Automation
package jaxp.test;

import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.sax.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.xml.sax.helpers.*;
import org.xml.sax.*;
import org.w3c.dom.*;
import java.io.*;
/**
 * A Class class.
 * <P>
 * @author Jan Hrabowski
 */
public class JaxpTest2 extends Object {

  /**
   * Constructor
   */
  public JaxpTest2() {
  }

  /**
   * main
   * @param args
   */
 public static void main(String[] args)
  throws TransformerConfigurationException,
  ParserConfigurationException,
  FileNotFoundException,
  IOException,
  SAXException,
  TransformerException,
  UnsupportedEncodingException
  {
  DocumentBuilderFactory dfactory =
    DocumentBuilderFactory.newInstance();
  dfactory.setNamespaceAware(true);
  DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
  Node doc = docBuilder.parse(new InputSource(args[0]));
    TransformerFactory transformerfactory = TransformerFactory.newInstance();

    Transformer transformer = transformerfactory.newTransformer();
    DOMSource domSource = new DOMSource(doc);
    SAXResult saxResult = new SAXResult(new TestHandler());
    transformer.transform(domSource, saxResult);
  }
}

============================TestHandler===============================
// Copyright (c) 2001 Brooks Automation
package jaxp.test;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * A Class class.
 * <P>
 * @author Jan Hrabowski
 */
public class TestHandler extends DefaultHandler {

  /**
   * Constructor
   */
  public TestHandler() {
  }

    public void startElement(String namespaceURI,
                             String sName, // simple name (localName)
                             String qName, // qualified name
                             Attributes attrs)
    throws SAXException
  {
   try {
   int i =
    attrs.getIndex("http://www.w3.org/2001/XMLSchema-instance";, "type");
    System.out.println("local name=" + attrs.getLocalName(i));
   String s =
    attrs.getValue("http://www.w3.org/2001/XMLSchema-instance";, "type");
  } catch (Exception e){ e.printStackTrace(); }
  }
}

Reply via email to