FasterXML / aalto-xml

Ultra-high performance non-blocking XML processor (Stax API + extensions)
Apache License 2.0
292 stars 70 forks source link

Add support for JEP-185 (JAXP-1.5) properties named ACCESS_EXTERNAL_ #77

Open pwagland opened 2 years ago

pwagland commented 2 years ago

Text stolen from https://github.com/FasterXML/woodstox/issues/51

Apparently there's a JEP to add Yet Another Set of configuration properties (to overlap with existing) ones:

http://openjdk.java.net/jeps/185

and since users will be trying to use them we'll probably need to add support.

It is further unfortunate these are added as System properties since that has all the problems of global variables; as well as the question of how these should interact with existing configuration settings.

This issue was found in our project when we tried to comply with SonarQubes warning that we should always disable DTD resolution.

We have a method:

  public static javax.xml.stream.XMLInputFactory buildXMLInputFactory(NameSpace ns)
  {
    javax.xml.stream.XMLInputFactory factory = javax.xml.stream.XMLInputFactory.newInstance();
    factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); // Compliant ← This is (XMLInputFactory.java:277)
    factory.setProperty(javax.xml.stream.XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
    factory.setProperty(javax.xml.stream.XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
    factory.setProperty(javax.xml.stream.XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.valueOf(ns == NameSpace.NAMESPACE_AWARE));
    return factory;
  }

And this fails with:

Caused by: java.lang.IllegalArgumentException: Unrecognized property 'http://javax.xml.XMLConstants/property/accessExternalDTD'
    at com.fasterxml.aalto.impl.CommonConfig.setProperty(CommonConfig.java:135)
    at com.fasterxml.aalto.in.ReaderConfig.setProperty(ReaderConfig.java:373)
    at com.fasterxml.aalto.stax.InputFactoryImpl.setProperty(InputFactoryImpl.java:229)
    at com.company.xml.XMLInputFactory.buildXMLInputFactory(XMLInputFactory.java:277)