-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b38
-
generic
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2078498 | 1.3.0 | Kohsuke Kawaguchi | P3 | Closed | Fixed | 1.3 |
Name: eaR10174 Date: 12/18/2003
The methods
javax.xml.validation.TypeInfoProvider.getAttributeTypeInfo(int index)
javax.xml.validation.TypeInfoProvider.isIdAttribute(int index)
throw IllegalArgumentException instead of IndexOutOfBoundsException in case when the index is
invalid. The methods should throw IndexOutOfBoundsException according to the javadoc.
The bug affects new JCK1.5 tests (not integrated yet):
api/javax_xml/validation/TypeInfoProvider/index.html#GetAttrTypeInfo[GetAttrTypeInfo002]
api/javax_xml/validation/TypeInfoProvider/index.html#GetAttrTypeInfo[GetAttrTypeInfo003]
api/javax_xml/validation/TypeInfoProvider/index.html#IsIdAttribute[IsIdAttribute002]
api/javax_xml/validation/TypeInfoProvider/index.html#IsIdAttribute[IsIdAttribute003]
The following test fails running on JDK 1.5.0-beta-b31.
See below the test source and the execution log:
------------------------------------test.java-----------------------------
import java.io.StringReader;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.TypeInfoProvider;
import javax.xml.validation.ValidatorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
public class test {
public static final String XSD = "<?xml version='1.0'?>\n"
+ "<schema xmlns='http://www.w3.org/2001/XMLSchema'\n"
+ " xmlns:test='jaxp13_test'\n"
+ " targetNamespace='jaxp13_test'\n"
+ " elementFormDefault='qualified'>\n"
+ " <element name='test'>\n"
+ " <complexType>\n"
+ " <sequence>\n"
+ " <element name='child' type='string'/>\n"
+ " </sequence>\n"
+ " <attribute name='id' type='date'/>\n"
+ " </complexType>\n"
+ " </element>\n"
+ "</schema>\n";
public static final String XML = "<?xml version='1.0'?>\n"
+ "<ns:test xmlns:ns='jaxp13_test' id='2003-12-02'>\n"
+ " <ns:child>123abc</ns:child>\n"
+ "</ns:test>\n";
private ValidatorHandler createValidatorHandler(String xsd)
throws SAXException {
SchemaFactory schemaFactory =
SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
StringReader reader = new StringReader(xsd);
StreamSource xsdSource = new StreamSource(reader);
Schema schema = schemaFactory.newSchema(xsdSource);
return schema.newValidatorHandler();
}
private XMLReader createXMLReader() throws ParserConfigurationException, SAXException {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
if (!parserFactory.isNamespaceAware()) {
parserFactory.setNamespaceAware(true);
}
return parserFactory.newSAXParser().getXMLReader();
}
private void parse(XMLReader xmlReader, String xml) throws SAXException, IOException {
StringReader reader = new StringReader(xml);
InputSource inSource = new InputSource(reader);
xmlReader.parse(inSource);
}
public static void main(String argv[]) {
try {
new test().run();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
public void run() throws Exception {
XMLReader xmlReader = createXMLReader();
final ValidatorHandler validatorHandler = createValidatorHandler(XSD);
xmlReader.setContentHandler(validatorHandler);
DefaultHandler handler = new DefaultHandler() {
public void startElement(String uri, String localName,
String qName, Attributes attributes)
throws SAXException {
if (!"ns:test".equals(qName)) {
return;
}
TypeInfoProvider infoProvider = null;
synchronized (validatorHandler) {
infoProvider = validatorHandler.getTypeInfoProvider();
}
if (infoProvider == null) {
throw new SAXException("Can't obtain TypeInfoProvider object.");
}
try {
infoProvider.getAttributeTypeInfo(-1);
throw new SAXException("IndexOutOfBoundsException was not thrown.");
} catch (IndexOutOfBoundsException e) {
System.out.println("getAttributeTypeInfo(-1): OK");
} catch (Exception e) {
System.out.println("getAttributeTypeInfo(-1): " + e.toString());
}
System.out.println("");
try {
infoProvider.isIdAttribute(-1);
throw new SAXException("IndexOutOfBoundsException was not thrown.");
} catch (IndexOutOfBoundsException e) {
System.out.println("isIdAttribute(-1): OK");
} catch (Exception e) {
System.out.println("isIdAttribute(-1): " + e.toString());
}
}
};
validatorHandler.setContentHandler(handler);
parse(xmlReader, XML);
}
}
--------------------------------------------------------------------------
% java -showversion test
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b31)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b31, mixed mode)
getAttributeTypeInfo(-1): java.lang.IllegalArgumentException
isIdAttribute(-1): java.lang.IllegalArgumentException
--------------------------------------------------------------------------
======================================================================
The methods
javax.xml.validation.TypeInfoProvider.getAttributeTypeInfo(int index)
javax.xml.validation.TypeInfoProvider.isIdAttribute(int index)
throw IllegalArgumentException instead of IndexOutOfBoundsException in case when the index is
invalid. The methods should throw IndexOutOfBoundsException according to the javadoc.
The bug affects new JCK1.5 tests (not integrated yet):
api/javax_xml/validation/TypeInfoProvider/index.html#GetAttrTypeInfo[GetAttrTypeInfo002]
api/javax_xml/validation/TypeInfoProvider/index.html#GetAttrTypeInfo[GetAttrTypeInfo003]
api/javax_xml/validation/TypeInfoProvider/index.html#IsIdAttribute[IsIdAttribute002]
api/javax_xml/validation/TypeInfoProvider/index.html#IsIdAttribute[IsIdAttribute003]
The following test fails running on JDK 1.5.0-beta-b31.
See below the test source and the execution log:
------------------------------------test.java-----------------------------
import java.io.StringReader;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.TypeInfoProvider;
import javax.xml.validation.ValidatorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
public class test {
public static final String XSD = "<?xml version='1.0'?>\n"
+ "<schema xmlns='http://www.w3.org/2001/XMLSchema'\n"
+ " xmlns:test='jaxp13_test'\n"
+ " targetNamespace='jaxp13_test'\n"
+ " elementFormDefault='qualified'>\n"
+ " <element name='test'>\n"
+ " <complexType>\n"
+ " <sequence>\n"
+ " <element name='child' type='string'/>\n"
+ " </sequence>\n"
+ " <attribute name='id' type='date'/>\n"
+ " </complexType>\n"
+ " </element>\n"
+ "</schema>\n";
public static final String XML = "<?xml version='1.0'?>\n"
+ "<ns:test xmlns:ns='jaxp13_test' id='2003-12-02'>\n"
+ " <ns:child>123abc</ns:child>\n"
+ "</ns:test>\n";
private ValidatorHandler createValidatorHandler(String xsd)
throws SAXException {
SchemaFactory schemaFactory =
SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
StringReader reader = new StringReader(xsd);
StreamSource xsdSource = new StreamSource(reader);
Schema schema = schemaFactory.newSchema(xsdSource);
return schema.newValidatorHandler();
}
private XMLReader createXMLReader() throws ParserConfigurationException, SAXException {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
if (!parserFactory.isNamespaceAware()) {
parserFactory.setNamespaceAware(true);
}
return parserFactory.newSAXParser().getXMLReader();
}
private void parse(XMLReader xmlReader, String xml) throws SAXException, IOException {
StringReader reader = new StringReader(xml);
InputSource inSource = new InputSource(reader);
xmlReader.parse(inSource);
}
public static void main(String argv[]) {
try {
new test().run();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
public void run() throws Exception {
XMLReader xmlReader = createXMLReader();
final ValidatorHandler validatorHandler = createValidatorHandler(XSD);
xmlReader.setContentHandler(validatorHandler);
DefaultHandler handler = new DefaultHandler() {
public void startElement(String uri, String localName,
String qName, Attributes attributes)
throws SAXException {
if (!"ns:test".equals(qName)) {
return;
}
TypeInfoProvider infoProvider = null;
synchronized (validatorHandler) {
infoProvider = validatorHandler.getTypeInfoProvider();
}
if (infoProvider == null) {
throw new SAXException("Can't obtain TypeInfoProvider object.");
}
try {
infoProvider.getAttributeTypeInfo(-1);
throw new SAXException("IndexOutOfBoundsException was not thrown.");
} catch (IndexOutOfBoundsException e) {
System.out.println("getAttributeTypeInfo(-1): OK");
} catch (Exception e) {
System.out.println("getAttributeTypeInfo(-1): " + e.toString());
}
System.out.println("");
try {
infoProvider.isIdAttribute(-1);
throw new SAXException("IndexOutOfBoundsException was not thrown.");
} catch (IndexOutOfBoundsException e) {
System.out.println("isIdAttribute(-1): OK");
} catch (Exception e) {
System.out.println("isIdAttribute(-1): " + e.toString());
}
}
};
validatorHandler.setContentHandler(handler);
parse(xmlReader, XML);
}
}
--------------------------------------------------------------------------
% java -showversion test
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b31)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b31, mixed mode)
getAttributeTypeInfo(-1): java.lang.IllegalArgumentException
isIdAttribute(-1): java.lang.IllegalArgumentException
--------------------------------------------------------------------------
======================================================================
- backported by
-
JDK-2078498 TypeInfoProvider: attributes info accessing methods throw IAE instead of IOOBE
-
- Closed
-