Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2458

XMLFactory caches JAXP implementations that could be reloaded which will cause ClassCastExceptions

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: kernel
    • Labels:
      None
    • Environment:
      When running on application servers and application ships with it's own JAXP implementation

      Description

      XMLFactory caches JAXP implementations in _saxFactories and _domFactories fields if those JAXP implementations are reloaded, such as when they originate from application that is deployed in a application server and the application is restarted or redeployed – ClassCast exception could (depending on classloading) ensue.

      Consider an application that ships it's own JAXP implementation (e.g. Sun JAXP RI), which contains META-INF/services/javax.xml.parsers.DocumentBuilderFactory or SAXParserFactory and a application server that ships with OpenJPA (e.g. IBM WebSphere). If that application is the first that uses OpenJPA it's JAXP implementation will be used and cached in the org.apache.openjpa.lib.xml.XMLFactory fields _saxFactories and _domFactories. If the application is restarted then new versions of JAXP implementation classes are loaded in a new classloader. This causes ClassCastException, such as:

      java.lang.ClassCastException: com.sun.org.apache.xerces.internal.parsers.XIncludeAwareParserConfiguration incompatible with com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration
      at com.sun.org.apache.xerces.internal.parsers.DOMParser.(DOMParser.java:177)
      at com.sun.org.apache.xerces.internal.parsers.DOMParser.(DOMParser.java:161)
      at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.(DocumentBuilderImpl.java:159)
      at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(DocumentBuilderFactoryImpl.java:115)
      at org.apache.openjpa.lib.xml.XMLFactory.getDOMParser(XMLFactory.java:107)
      at org.apache.openjpa.jdbc.sql.SQLErrorCodeReader.parse(SQLErrorCodeReader.java:107)
      at org.apache.openjpa.jdbc.sql.DBDictionary.endConfiguration(DBDictionary.java:4718)
      at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:531)
      at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:456)
      at org.apache.openjpa.jdbc.sql.DBDictionaryFactory.newDBDictionary(DBDictionaryFactory.java:199)
      at org.apache.openjpa.jdbc.sql.DBDictionaryFactory.newDBDictionary(DBDictionaryFactory.java:66)
      at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:579)
      at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1518)
      at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:531)
      at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:456)
      at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:104)
      at org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68)
      at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
      at org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:949)
      at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:940)
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.getMetamodel(EntityManagerFactoryImpl.java:346)
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.getCriteriaBuilder(EntityManagerFactoryImpl.java:333)
      

      The only way I see that this could be fixed is not to cache the JAXP implementations, or to cache them in an application specific cache thats tied to EntityManager, and not to global OpenJPA state.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              zregvart Zoran Regvart
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: