Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible ClassCastException when createXMLResource() uses xerces #187

Closed
sosnut opened this issue Mar 27, 2018 · 1 comment
Closed

Possible ClassCastException when createXMLResource() uses xerces #187

sosnut opened this issue Mar 27, 2018 · 1 comment

Comments

@sosnut
Copy link
Contributor

sosnut commented Mar 27, 2018

When xerces is used in the application, createXMLResource() can send the following exception:
org.apache.xerces.parsers.XIncludeAwareParserConfiguration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration

java.lang.ClassCastException: org.apache.xerces.parsers.XIncludeAwareParserConfiguration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration
	at org.apache.xerces.parsers.DOMParser.<init>(Unknown Source)
	at org.apache.xerces.parsers.DOMParser.<init>(Unknown Source)
	at org.apache.xerces.jaxp.DocumentBuilderImpl.<init>(Unknown Source)
	at org.apache.xerces.jaxp.DocumentBuilderImpl.<init>(Unknown Source)
	at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setFeature(Unknown Source)
	at com.openhtmltopdf.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:200)
	at com.openhtmltopdf.resource.XMLResource$XMLResourceBuilder.access$100(XMLResource.java:164)
	at com.openhtmltopdf.resource.XMLResource.load(XMLResource.java:77)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.setDocumentFromStringP(PdfBoxRenderer.java:349)
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.<init>(PdfBoxRenderer.java:255)
	at com.openhtmltopdf.pdfboxout.PdfRendererBuilder.buildPdfRenderer(PdfRendererBuilder.java:106)
	at com.openhtmltopdf.pdfboxout.PdfRendererBuilder.run(PdfRendererBuilder.java:84)

(Observed with Oracle Jdk 1.8.0_66, openhtmltopdf 0.0.1-RC12).

By default openhtmltopdf does not use xerces (but in some cases it seems to pick xerces implementation of DocumentBuilderFactory if it's used elsewhere in the application; I suppose it would be better to use the internal JAXP implementation from com.sun.org.apache.xerces.internal.jaxp unless specified otherwise – since xerces is quite old now).

This issue seems similar to issue #54 (except that Xerces is involved instead of Xalan).

(The problem can happen for example when the application uses spring-security-saml 1.0.3 – which depends on xerces 2.10.0)

@sosnut
Copy link
Contributor Author

sosnut commented Mar 27, 2018

I am working on a fix that would use a solution similar to what was done for #54 in a737e96

sosnut added a commit to sosnut/openhtmltopdf that referenced this issue Mar 28, 2018
…n and adding a way to bypass it

Specifying "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl" as the default DocumentBuilderFactory, in BaseRendererBuilder. (This is the factory that is used by default, but an application may depend on an other parser which could provide an incompatible builder factory).

Adding method useDocumentBuilderFactoryImplementationClass(), to be able to use another implementation (or the DocumentBuilderFactory currently available in the application, if null is passed) if necessary.
danfickle added a commit that referenced this issue Mar 29, 2018
#187 Specifying default DocumentBuilderFactory implementation and add way to bypass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants