I've this sonarqube issue in my java project: Disable access to external entities in XML parsing. I've implemented the compliant solution that is like this:
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
but now when i debug the code i've this exception:
java.lang.IllegalArgumentException: Not supported: http://javax.xml.XMLConstants/property/accessExternalDTD
what am I doing wrong?
The implementation of Transformer Factory in your application may not support the properties XMLConstants.ACCESS_EXTERNAL_DTD and XMLConstants.ACCESS_EXTERNAL_STYLESHEET.
You can try creating instance of Transformer Factory in this way :
instead of your actual code :