Commons Betwixt
  1. Commons Betwixt
  2. BETWIXT-57

Class loader problem in JBoss version 4.0.4GA

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      JBoss application server version 4.0.4GA. Probably affects most versions of JBoss

      Description

      When using betwixt in a JBoss application, "Class not found" exceptions get thrown when Class.forName methods are called in classes org.apache.commons.betwixt.digester.ElementRule and org.apache.commons.betwixt.digester.ClassRule. Specifically the Class.forName method uses the system class loader to load classes and in JBoss the classpath normally does not contain the application jar files. The fix is very simple. The Class.forName method calls in both the classes were replaced with the following code lines in ElementRule and similar changes were made in ClassRule as well. This fix ensures that the appropriate class loader is used for loading classes and is similar to the fix made in log4j.

      ClassLoader loader = Thread.currentThread().getContextClassLoader();
      if (loader == null)

      { loader = Class.forName(implementationClass).getClassLoader(); //Class clazz = Class.forName(implementationClass); }

      Class clazz = loader.loadClass(implementationClass);
      descriptor.setImplementationClass(clazz);

        Activity

        Hide
        Simon Kitching added a comment -

        Ok, I've made this default to "true". I've also ensured that when set to false, lookup is relative to the classloader that loaded Betwixt, not the one that loaded Digester. See r495842, r495843.

        Show
        Simon Kitching added a comment - Ok, I've made this default to "true". I've also ensured that when set to false, lookup is relative to the classloader that loaded Betwixt, not the one that loaded Digester. See r495842, r495843.
        Hide
        Robert Burrell Donkin added a comment -

        I was a little concerned about the effects on existing installations of using the context classloader but Betwixt is only a 0.x so feel free to break the semantics if it's right thing to do and you documentation it at the bottom of tasks.xml.

        Please feel free to go ahead and add more javadocs (and documentation, if you can find some time)

        Show
        Robert Burrell Donkin added a comment - I was a little concerned about the effects on existing installations of using the context classloader but Betwixt is only a 0.x so feel free to break the semantics if it's right thing to do and you documentation it at the bottom of tasks.xml. Please feel free to go ahead and add more javadocs (and documentation, if you can find some time)
        Hide
        Simon Kitching added a comment -

        Robert, I see that the new useContextClassLoader attribute defaults to false.

        In Digester it defaults to false, but that is mainly because this feature was added after Digester was already widely used and at a 1.x release. Changing the existing behaviour would therefore not be acceptable.

        Perhaps for Betwixt it should default to true instead? Or is it too late already to change existing behaviour?

        Either way, it would be nice if the javadoc indicated what the default behaviour is...

        Show
        Simon Kitching added a comment - Robert, I see that the new useContextClassLoader attribute defaults to false. In Digester it defaults to false, but that is mainly because this feature was added after Digester was already widely used and at a 1.x release. Changing the existing behaviour would therefore not be acceptable. Perhaps for Betwixt it should default to true instead? Or is it too late already to change existing behaviour? Either way, it would be nice if the javadoc indicated what the default behaviour is...
        Hide
        Robert Burrell Donkin added a comment -

        Fix committed.

        Show
        Robert Burrell Donkin added a comment - Fix committed.
        Hide
        Robert Burrell Donkin added a comment -

        There are issues with switching universally to using the context classloader: too many containers do not set this classloader correctly. Digester rules should use the classloader provided by Digester. So, the Betwixt rules should use the Digester classloader. However, the Digester implemetation is not exposed by XmlIntrospector. So, this setting needs to be added into the IntrospectionConfiguration.

        I've committed these changes into trunk.

        Now, when using Betwixt in a container like JBoss with a well behaved context classloader, setUseContextClassLoader(true) should called on IntrospectionConfiguration for the XMLIntrospector. This should produce the same result as the fix above. Please try the latest code and open this again if this fix doesn't work.

        Show
        Robert Burrell Donkin added a comment - There are issues with switching universally to using the context classloader: too many containers do not set this classloader correctly. Digester rules should use the classloader provided by Digester. So, the Betwixt rules should use the Digester classloader. However, the Digester implemetation is not exposed by XmlIntrospector. So, this setting needs to be added into the IntrospectionConfiguration. I've committed these changes into trunk. Now, when using Betwixt in a container like JBoss with a well behaved context classloader, setUseContextClassLoader(true) should called on IntrospectionConfiguration for the XMLIntrospector. This should produce the same result as the fix above. Please try the latest code and open this again if this fix doesn't work.

          People

          • Assignee:
            Unassigned
            Reporter:
            Surjit Sen
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development