NOTE: The current preferred location for bug reports is the GitHub issue tracker.
Bug 663 - HtmlParser.setFeature throws Exception when setting 'immutable' values
HtmlParser.setFeature throws Exception when setting 'immutable' values
Status: RESOLVED FIXED
Product: Validator.nu
Classification: Unclassified
Component: HTML parser
HEAD
All All
: P2 normal
Assigned To: Nobody
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-10-05 23:38 CEST by Pavol Vaskovic
Modified: 2011-05-19 15:53 CEST (History)
1 user (show)

See Also:


Attachments
possible fix (3.53 KB, patch)
2009-10-06 00:09 CEST, Pavol Vaskovic
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pavol Vaskovic 2009-10-05 23:38:57 CEST
In nu.validator.htmlparser version 1.2.0, setting "immutable" features to the supported value throws exceptions.

I've tried using htmlparser with Saxon XSLT processor as follows:
...
XMLReader htmlParser = new HtmlParser(ALTER_INFOSET);
transformer.transform(new SAXSource(htmlParser, new InputSource(input)), 
                      new StreamResult(output));
but I've got:

org.specs.runner.UserError: net.sf.saxon.trans.XPathException: The SAX2 parser nu.validator.htmlparser.sax.HtmlParser does not recognize the 'namespaces' feature
	at net.sf.saxon.event.Sender.configureParser(Sender.java:509)
	at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:304)
	at net.sf.saxon.event.Sender.send(Sender.java:193)
	at net.sf.saxon.event.Sender.send(Sender.java:50)
	at net.sf.saxon.Controller.transform(Controller.java:1611)

because Saxon tries to configure the XML parser like this:
// user-supplied parser: ensure that it meets the namespace requirements
parser.setFeature("http://xml.org/sax/features/namespaces", true);
parser.setFeature("http://xml.org/sax/features/namespace-prefixes", false);

I believe the current implementation is in violation of method's contract as specified in Javadoc for org.xml.sax.XMLReader.setFeature:
...
All XMLReaders are required to support setting http://xml.org/sax/features/namespaces to true and http://xml.org/sax/features/namespace-prefixes to false.
Comment 1 Pavol Vaskovic 2009-10-06 00:09:10 CEST
Created attachment 119 [details]
possible fix

This patch solves the issue by checking if the value being set matches the immutable value. It also delegates the throwing of SAXNotRecognizedException to the getFeature.
Comment 2 Henri Sivonen 2011-05-19 15:53:25 CEST
This has already been fixed.