You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Sean Hennessy <sh...@edupoint.com> on 2000/11/06 17:46:34 UTC
RE: wrong exception thrown when setting features in Xerces-J 1.2.
1
Perhaps it is not a bug but a problem with the documentation.
I think it is appropriate that when it has no knowledge of the feature in
question it generates a general exception in that it is saying it does not
know what is being asked of it.
This is different from acknowledging that a known specific feature is not
implemented or available.
> -----Original Message-----
> From: Elliotte Rusty Harold [mailto:elharo@metalab.unc.edu]
> Sent: Monday, November 06, 2000 10:55 AM
> To: xerces-j-dev@xml.apache.org
> Subject: Bug: wrong exception thrown when setting features in Xerces-J
> 1.2.1
>
>
> According to the SAX2 documentation "if the application
> attempts to set a feature state or property value that the XML reader
> cannot support at that time, or attempts to modify a feature
> or property
> when it is read-only, the XML reader throws a
> SAXNotSupportedException."
>
> Xerces-J 1.2.1 is not doing this, at least for the
> http://xml.org/sax/features/validation feature. Instead, it
> is throwing
> a SAXException rather than the more specific subclass. Furthermore the
> exception message is not getting set here.
>
> Here's a Java program that demonstrates the bug. Run it across any XML
> document to see the problem:
>
> import org.xml.sax.*;
> import org.xml.sax.helpers.*;
> import java.io.IOException;
>
>
> public class FeatureTest extends DefaultHandler {
>
> private XMLReader parser;
>
> public void endElement(String namespaceURI, String localName,
> String qualifiedName) {
>
> try {
>
> parser.setFeature("http://xml.org/sax/features/validation", true);
> System.out.println("Failed Silently");
> }
> catch (SAXNotSupportedException e) {
> // This is what should be thrown
> System.out.println("SAXNotSupportedException: " + e);
> }
> catch (SAXNotRecognizedException e) {
> System.out.println("SAXNotRecognizedException: " + e);
> }
> catch (SAXException e) {
> // This is what is thrown
> System.out.println("SAXException: " + e);
> }
>
> }
>
> public static void main(String[] args) {
>
> FeatureTest handler = new FeatureTest();
> try {
> handler.parser = XMLReaderFactory.createXMLReader(
> "org.apache.xerces.parsers.SAXParser");
> }
> catch (SAXException ee) {
> System.err.println("Couldn't locate a SAX parser");
> return;
> }
>
> if (args.length == 0) {
> System.out.println(
> "Usage: java EventReporter URL1 URL2...");
> }
>
> // Install the Document Handler
> handler.parser.setContentHandler(new FeatureTest());
>
> // start parsing...
> for (int i = 0; i < args.length; i++) {
>
> // command line should offer URIs or file names
> try {
> handler.parser.parse(args[i]);
> }
> catch (SAXParseException e) { // well-formedness error
> System.out.println(args[i] + " is not well formed.");
> System.out.println(e.getMessage()
> + " at line " + e.getLineNumber()
> + ", column " + e.getColumnNumber());
> }
> catch (SAXException e) { // some other kind of error
> System.out.println("SAXException" + e.getMessage());
> }
> catch (IOException e) {
> System.out.println("Could not report on " + args[i]
> + " because of the IOException " + e);
> }
>
> }
>
> }
>
> }
>
> --
> +-----------------------+------------------------+-------------------+
> | Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
> +-----------------------+------------------------+------------
> -------+
> | Java I/O (O'Reilly & Associates, 1999) |
> | http://metalab.unc.edu/javafaq/books/javaio/ |
> | http://www.amazon.com/exec/obidos/ISBN=1565924851/cafeaulaitA/ |
> +----------------------------------+---------------------------------+
> | Read Cafe au Lait for Java News:
> http://metalab.unc.edu/javafaq/ |
> | Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/ |
> +----------------------------------+---------------------------------+
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>
RE: wrong exception thrown when setting features in Xerces-J 1.2.
1
Posted by Elliotte Rusty Harold <el...@metalab.unc.edu>.
I withdraw the bug report. It turns out to have been a bug in my
code. Xerces is doing exactly what it's supposed to be doing here.
This should teach me to try to write quick and dirty test cases that
violate good coding practices.
--
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| The XML Bible (IDG Books, 1999) |
| http://metalab.unc.edu/xml/books/bible/ |
| http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://metalab.unc.edu/javafaq/ |
| Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/ |
+----------------------------------+---------------------------------+