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
Classification: Unclassified
Component: HTML parser
All All
: P2 normal
Assigned To: Nobody
Depends on:
  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:

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

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(
	at net.sf.saxon.event.Sender.sendSAXSource(
	at net.sf.saxon.event.Sender.send(
	at net.sf.saxon.event.Sender.send(
	at net.sf.saxon.Controller.transform(

because Saxon tries to configure the XML parser like this:
// user-supplied parser: ensure that it meets the namespace requirements
parser.setFeature("", true);
parser.setFeature("", 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 to true and 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.