bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug xml/31814] New: Element hasAttribute returns true even if element d


From: fullung at gmail dot com
Subject: [Bug xml/31814] New: Element hasAttribute returns true even if element doesn't have specified attribute when document is validated (and maybe when it uses an entity resolver)
Date: 4 May 2007 10:08:11 -0000

I'm running the latest GNU Classpath from CVS as of 2007/05/04 10:00 GMT+2 with
IKVM.NET, also the latest from CVS.

Code to reproduce:

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class HasAttributeBug {
        private static class MyEntityResolver implements EntityResolver {
                public InputSource resolveEntity(String publicId, String
systemId)
                                throws SAXException, IOException {
                        return new InputSource(new
FileInputStream("spring-beans-2.0.dtd"));
                }
        }

        private static void check(boolean validate) throws Exception {
                EntityResolver entityResolver = null;
                final String xml;
                if (validate) {
                        xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                                        + "<!DOCTYPE beans PUBLIC
\"-//SPRING//DTD BEAN 2.0//EN\"
\"http://www.springframework.org/dtd/spring-beans-2.0.dtd\";>"
                                        + "<beans><bean><property
name=\"name\"><value>value</value></property></bean></beans>";
                        entityResolver = new MyEntityResolver();
                } else {
                        xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                                        + "<beans><bean><property
name=\"name\"><value>value</value></property></bean></beans>";
                }
                DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
                factory.setNamespaceAware(false);
                factory.setValidating(validate);
                DocumentBuilder docBuilder = factory.newDocumentBuilder();
                docBuilder.setEntityResolver(entityResolver);
                InputSource inputSource = new InputSource(new
ByteArrayInputStream(xml.getBytes()));
                Document doc = docBuilder.parse(inputSource);
                Element ele = (Element)
doc.getElementsByTagName("property").item(0);
                boolean hasRefAttribute = ele.hasAttribute("ref");
                boolean hasValueAttribute = ele.hasAttribute("value");
                System.out.println(hasRefAttribute);
                System.out.println(hasValueAttribute);
        }

        public static void main(String[] args) throws Exception {
                check(false);
                check(true);
        }
}

On Sun JDK 1.5.0_10 this prints (as expected):

false
false
false
false

On GNU Classpath/IKVM.NET this prints:

false
false
true
true

i. e. with an entity resolver in place and validating set to true, hasAttribute
returns true when it should return false.

DTD can be downloaded from
http://www.springframework.org/dtd/spring-beans-2.0.dtd.


-- 
           Summary: Element hasAttribute returns true even if element
                    doesn't have specified attribute when document is
                    validated (and maybe when it uses an entity resolver)
           Product: classpath
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: xml
        AssignedTo: dog at gnu dot org
        ReportedBy: fullung at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31814





reply via email to

[Prev in Thread] Current Thread [Next in Thread]