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

Get NoClassDefFoundError when Woodstox is not present #100

sweetnavelorange opened this Issue Feb 4, 2015 · 0 comments


None yet
1 participant

sweetnavelorange commented Feb 4, 2015

When we tried to use hapi-fhir for parsing/serializing in an environment without Woodstox, the following happened:

java.lang.NoClassDefFoundError: com/ctc/wstx/stax/WstxInputFactory
    at ca.uhn.fhir.util.XmlUtil.getOrCreateInputFactory(


This is caused by the code using an instanceof check to see if the factory is in fact a Woodstox factory before adding Woodstox-specific properties. The following patch fixes the issue for us when Woodstox is not present (using the JRE-supplied StAX implementation); I am unable to verify that it does what you want with Woodstox, in particular if the actual runtime class of the factory is not exactly the named class. Please consider it a starting point.

diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/
index 23ec3ed..83ce96a 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/
@@ -211,7 +211,7 @@ public class XmlUtil {
             * being used (e.g. glassfish) so we don't set them there.

-           if (inputFactory instanceof com.ctc.wstx.stax.WstxInputFactory) {
+           if ("com.ctc.wstx.stax.WstxInputFactory".equals(inputFactory.getClass().getName())) {
                // inputFactory.setProperty(WstxInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
                inputFactory.setProperty(WstxInputProperties.P_UNDECLARED_ENTITY_RESOLVER, XML_RESOLVER);
@@ -317,7 +317,7 @@ public class XmlUtil {
             * Note that these properties are Woodstox specific and they cause a crash in environments where SJSXP is
             * being used (e.g. glassfish) so we don't set them there.
-           if (outputFactory instanceof WstxOutputFactory) {
+           if ("com.ctc.wstx.stax.WstxOutputFactory".equals(outputFactory.getClass().getName())) {
                outputFactory.setProperty(XMLOutputFactory2.P_TEXT_ESCAPER, new MyEscaper());
            ourOutputFactory = outputFactory;

@jamesagnew jamesagnew closed this in 37e2abb Feb 4, 2015

jamesagnew added a commit that referenced this issue Feb 5, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment