Check the JAXB context factory initialization class

This rule is related to Java Architecture for XML Binding (JAXB) initialization class changes and conflicts that can occur when migrating from WebSphere Application Server versions prior to V7.0. There are two JAXB migration scenarios that have caused issues with customer applications. The first is related to applications migrated from the WebSphere 6.1 Feature Pack for Web Services. The second scenario is related to customer applications that package a JAXB implementation and are migrated to WebSphere V7.0 or later.

In WebSphere V7.0, JAXB 2.1 is shipped as part the Java 6 run time. Prior to V7.0, the WebSphere 6.1 Feature Pack for Web Services shipped JAXB 2.0 which used a different initialization class than is used in JAXB 2.1 or 2.2 (V8.0). If the application specifies to use the old initialization class, class not found exceptions can be generated when the application is run. The initialization class can be defined using the javax.xml.bind.context.factory property. The old initialization class is com.sun.xml.bind.ContextFactory. If the old class name is set on the javax.xml.bind.context.factory property, you will get a java.lang.ClassNotFoundException when using the JAXB libraries available with Java 6.

This rule scans for the javax.xml.bind.JAXBContext.newInstance method which is used to obtain a JAXBContext. If you are using JAXB, you should check your application for use of the old context factory. The rule will also detect the string literals "com.sun.xml.bind.ContextFactory" or "com.sun.xml.bind.DefaultJAXBContextImpl" in Java code, but it does not scan property files where these values are often set. They can also be set at Java system properties.

JAXB properties are commonly loaded from a jaxb.properties file. Manually scan your application property files to determine if the old context factory is defined.

To scan the the properties files in Eclipse, select Search > File.... In the Containing text field, type com.sun.xml.bind.ContextFactory. In the File name patterns field, type *.properties. Repeat the search for the string com.sun.xml.bind.DefaultJAXBContextImpl.

When using JAXB in WebSphere V7 or V8, the default initialization class is com.ibm.xml.xlxp2.jaxb.JAXBContextFactory if no javax.xml.bind.context.factory property is set.

For the second scenario, customers who packaged a JAXB implementation as part of their application prior to V7 can also experience the issues just described or behavior changes when migrating to WebSphere V7.0 or later. This occurs when the JAXB 2.1 or 2.2 versions provided as part of the Java run time get loaded rather than the JAXB implementation shipped with the application. The article Enabling a third-party JAX-WS application in WebSphere Application Server V7 describes how to work around the class loader issues if you want to continue to use your JAXB implementation.

For additional information, see the following references