Commons Digester
  1. Commons Digester
  2. DIGESTER-10

[digester] ParserFeatureSetterFactory uses a wrong method to detect the use of Xerces parser

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

      Description

      The ParserFeatureSetterFactory relies on the presence of the
      org.apache.xerces.impl.Version class in the classpath to determine that the
      Xerces parser is being used. However it's not always the case and it's possible
      that a different parser is actually being used. In this case the non-standard
      features that are set on the parser factory in the XercesParser class will cause
      an exception to be thrown. The following exception is thrown when using the
      Crimson XML parser with Xercer parser in the classpath:

      org.xml.sax.SAXNotRecognizedException: Feature:
      http://apache.org/xml/features/validation/dynamic
      at org.apache.crimson.parser.XMLReaderImpl.setFeature(XMLReaderImpl.java:219)
      at org.apache.crimson.jaxp.SAXParserImpl.setFeatures(SAXParserImpl.java:150)
      at org.apache.crimson.jaxp.SAXParserImpl.<init>(SAXParserImpl.java:133)
      at
      org.apache.crimson.jaxp.SAXParserFactoryImpl.newSAXParserImpl(SAXParserFactoryImpl.java:113)
      at
      org.apache.crimson.jaxp.SAXParserFactoryImpl.setFeature(SAXParserFactoryImpl.java:141)
      at
      org.apache.commons.digester.parser.XercesParser.configureXerces(XercesParser.java:185)
      at
      org.apache.commons.digester.parser.XercesParser.newSAXParser(XercesParser.java:138)
      at
      org.apache.commons.digester.ParserFeatureSetterFactory.newSAXParser(ParserFeatureSetterFactory.java:71)
      at org.apache.commons.digester.Digester.getParser(Digester.java:692)
      at org.apache.commons.digester.Digester.getXMLReader(Digester.java:899)
      at org.apache.commons.digester.Digester.parse(Digester.java:1647)

      This problem can be easily reproduced on JDK 1.4.2, which bundles the Crimson
      parser, by forcing a non-Xerces using the following:

      System.setProperty("javax.xml.parsers.SAXParserFactory",
      "org.apache.crimson.jaxp.SAXParserFactoryImpl");

      The test application must have the Xerces parser in the classpath. This bug is
      present both in versions 1.6 and 1.7.

        Activity

        Hide
        Simon Kitching added a comment -

        Agreed, it's a bug.

        Personally, though, I thing the whole ParserFeatureSetterFactory stuff is ugly
        and pointless. I would strongly recommend you don't use it at all. Instead set
        up your xml parser in whatever way you want then pass it as a parameter to the
        Digester constructor.

        Show
        Simon Kitching added a comment - Agreed, it's a bug. Personally, though, I thing the whole ParserFeatureSetterFactory stuff is ugly and pointless. I would strongly recommend you don't use it at all. Instead set up your xml parser in whatever way you want then pass it as a parameter to the Digester constructor.
        Hide
        Simon Kitching added a comment -

        PS: Thanks for reporting this, and providing such a clear diagnosis!

        Show
        Simon Kitching added a comment - PS: Thanks for reporting this, and providing such a clear diagnosis!
        Hide
        Peter Severin added a comment -

        Created an attachment (id=17853)
        Test case

        Here is the test case to help things out. The actual exception is actually
        this:
        java.lang.NullPointerException
        at org.apache.commons.digester.Digester.getXMLReader(Digester.java:899)

        at org.apache.commons.digester.Digester.parse(Digester.java:1685)
        at ParserBugTest.testParserDetection(ParserBugTest.java:35)

        The stack from the initial message is actually being logged and ignored in the
        Digester#getXMLReader method. I guess this is yet another bug.

        Show
        Peter Severin added a comment - Created an attachment (id=17853) Test case Here is the test case to help things out. The actual exception is actually this: java.lang.NullPointerException at org.apache.commons.digester.Digester.getXMLReader(Digester.java:899) at org.apache.commons.digester.Digester.parse(Digester.java:1685) at ParserBugTest.testParserDetection(ParserBugTest.java:35) The stack from the initial message is actually being logged and ignored in the Digester#getXMLReader method. I guess this is yet another bug.
        Hide
        Simon Kitching added a comment -

        This has been partially fixed in r385705; merely turning on validation now works
        fine no matter what parsers are present.

        Fixing parser detection so that method Digester.setSchema(String locn) works is
        more difficult, and not particularly useful. This method has therefore been
        documented as being broken, and a safer alternative recommended.

        Thanks for the bugreport.

        Show
        Simon Kitching added a comment - This has been partially fixed in r385705; merely turning on validation now works fine no matter what parsers are present. Fixing parser detection so that method Digester.setSchema(String locn) works is more difficult, and not particularly useful. This method has therefore been documented as being broken, and a safer alternative recommended. Thanks for the bugreport.
        Hide
        Simon Kitching added a comment -
            • COM-2891 has been marked as a duplicate of this bug. ***
        Show
        Simon Kitching added a comment - COM-2891 has been marked as a duplicate of this bug. ***

          People

          • Assignee:
            Unassigned
            Reporter:
            Peter Severin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development