Uploaded image for project: 'JBoss Enterprise Application Platform 4 and 5'
  1. JBoss Enterprise Application Platform 4 and 5
  2. JBPAPP-5167

CNFE Exceptions due to the wrong classloader being used

    XMLWordPrintable

Details

    • Workaround Exists
    • Hide

      public class MyEntityBean extends EJEntityBean {

      public void test(){
      // Assuming the CL is jacked up
      /*** WORKAROUND ***/
      ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader ( this.getClass().getClassLoader() );

      try

      { final Object obj = getJndiContext().lookup(jndiName); BeanLocal myBean =BeanLocal.class.cast(obj); System.out.println("ThreadBean test"); }

      catch (NamingException e2)

      { e2.printStackTrace(); }

      finally

      { /*** WORKAROUND ***/ Thread.currentThread().setContextClassLoader ( previousClassLoader ); }

      }

      Show
      public class MyEntityBean extends EJEntityBean { public void test(){ // Assuming the CL is jacked up /*** WORKAROUND ***/ ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader ( this.getClass().getClassLoader() ); try { final Object obj = getJndiContext().lookup(jndiName); BeanLocal myBean =BeanLocal.class.cast(obj); System.out.println("ThreadBean test"); } catch (NamingException e2) { e2.printStackTrace(); } finally { /*** WORKAROUND ***/ Thread.currentThread().setContextClassLoader ( previousClassLoader ); } }
    • Hide
      In two cases, the UnifiedClassLoader was used instead of an isolated EARs classloader. The first case occurred when a EJB2 Entity Bean was packaged inside of an isolated EAR and an EJB client was packaged in the same isolated EAR. When the EJB Entity Bean was passivated, a ClassNotFound exception was thrown. This was caused by the usage of UnifiedClassLoader instead of the EAR's isolated classloader. The second case occured when a deployed EJB2 Entity Bean had a local interface of the same name as an interface in the UnifiedClassLoader, resulting in a ClassCastException. The correct classloader is now used in both cases, and the errors no longer occur.
      Show
      In two cases, the UnifiedClassLoader was used instead of an isolated EARs classloader. The first case occurred when a EJB2 Entity Bean was packaged inside of an isolated EAR and an EJB client was packaged in the same isolated EAR. When the EJB Entity Bean was passivated, a ClassNotFound exception was thrown. This was caused by the usage of UnifiedClassLoader instead of the EAR's isolated classloader. The second case occured when a deployed EJB2 Entity Bean had a local interface of the same name as an interface in the UnifiedClassLoader, resulting in a ClassCastException. The correct classloader is now used in both cases, and the errors no longer occur.
    • Documented as Resolved Issue

    Description

      The unified classloader is used loading an interface from another jar archive in the /deploy when that interface is called from within a scoped EAR rather than the interface included in the EAR itself.

      Our tests show when an interface is in a jar in the deploy directory and also in the scoped my.ear Once passivate gets called from a class within the EAR, that calls that interface, then it throws a ClassCastException on ClassLocal myEJB = ClassLocal.class.cast(obj);
      However it is actually a ClassNotFound, looking in the debugger. We see that instead of using the context of the ejb which would be the EAR classloader, the unified classloader is used instead and hence the resulting exception

      Attachments

        Issue Links

          Activity

            People

              rhn-support-bmaxwell Brad Maxwell
              rhn-support-bmaxwell Brad Maxwell
              Elspeth Thorne Elspeth Thorne (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: