You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by "Heyman, Michael" <Mi...@sparta.com> on 2008/01/18 22:19:28 UTC

ClassCastException in OpenEJBInstance

While trying to straighten out my classpath, I got a ClassCastException
within OpenEJB code. I traced the cause down to trying to cast a
java.lang.Error (java.lang.NoClassDefFoundError) to a
java.lang.Exception in the init() method of OpenEJBInstance. A fix could
be:

In
/openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apach
e/openejb/loader/OpenEJBInstance.java:

    public void init(Properties props) throws Exception {
        try {
            init.invoke(null, props);
        } catch (InvocationTargetException e) {
 -          throw (Exception) e.getCause();
 +          if(e.getCause() instanceof Exception) {
 +              throw (Exception)e.getCause();
 +          } 
 +          throw (Error)e.getCause();
        } catch (Exception e) {
            throw new RuntimeException("OpenEJB.init: ", e);
        }
    }

(I don't know of any other types deriving from Throwable other than
Error and Exception so this should work).

-Michael Heyman

Re: ClassCastException in OpenEJBInstance

Posted by David Blevins <da...@visi.com>.
On Jan 18, 2008, at 1:19 PM, Heyman, Michael wrote:

> While trying to straighten out my classpath, I got a  
> ClassCastException
> within OpenEJB code. I traced the cause down to trying to cast a
> java.lang.Error (java.lang.NoClassDefFoundError) to a
> java.lang.Exception in the init() method of OpenEJBInstance. A fix  
> could
> be:
>
> In
> /openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/ 
> apach
> e/openejb/loader/OpenEJBInstance.java:
>
>    public void init(Properties props) throws Exception {
>        try {
>            init.invoke(null, props);
>        } catch (InvocationTargetException e) {
> -          throw (Exception) e.getCause();
> +          if(e.getCause() instanceof Exception) {
> +              throw (Exception)e.getCause();
> +          }
> +          throw (Error)e.getCause();
>        } catch (Exception e) {
>            throw new RuntimeException("OpenEJB.init: ", e);
>        }
>    }
>
> (I don't know of any other types deriving from Throwable other than
> Error and Exception so this should work).

Thanks, Michael!  I've checked in that fix.

We're doing a lot of work in this area right now in fact.  I've hacked  
up a couple tools that will help us get our classpath tightened up and  
help users know what should be added.

For example, these are the libraries currently needed to use the  
openejb-core jar (trunk version) for an embedded setup:

     activemq-core-4.1.1.jar (optional)
      activeio-core-3.0.0-incubator.jar
      backport-util-concurrent-2.1.jar
      commons-logging-1.1.jar
     activemq-ra-4.1.1.jar (optional)
      jmdns-1.0-RC2.jar
     asm-2.2.3.jar
     asm-commons-2.2.3.jar
      asm-tree-2.2.3.jar
     axis2-jaxws-api-1.3.jar
     commons-cli-1.1.jar
     commons-dbcp-1.3-SNAPSHOT.jar
      commons-pool-1.3.jar
     geronimo-activation_1.1_spec-1.0.jar
     geronimo-annotation_1.0_spec-1.1.jar
     geronimo-connector-2.1-SNAPSHOT.jar
     geronimo-ejb_3.0_spec-1.0.jar
     geronimo-interceptor_3.0_spec-1.0.jar
     geronimo-j2ee-connector_1.5_spec-1.1.1.jar
     geronimo-j2ee-deployment_1.1_spec-1.1.jar
     geronimo-j2ee-management_1.1_spec-1.0.jar
     geronimo-jacc_1.1_spec-1.0.jar
     geronimo-javamail_1.4_mail-1.2.jar
     geronimo-jaxr_1.0_spec-1.1.jar
     geronimo-jaxrpc_1.1_spec-1.1.jar
     geronimo-jms_1.1_spec-1.1.jar
     geronimo-jpa_3.0_spec-1.1.jar
     geronimo-jta_1.1_spec-1.1.jar
     geronimo-transaction-2.0.2.jar
     geronimo-ws-metadata_2.0_spec-1.1.1.jar
     jaxb-api-2.0.jar
     log4j-1.2.12.jar
     openejb-javaagent-3.0.0-SNAPSHOT.jar
     openejb-jee-3.0.0-SNAPSHOT.jar
      geronimo-stax-api_1.0_spec-1.0.jar
      jaxb-impl-2.0.5.jar
     openejb-loader-3.0.0-SNAPSHOT.jar
      geronimo-servlet_2.5_spec-1.1.jar
     openjpa-persistence-jdbc-1.0.1.jar (optional)
      openjpa-jdbc-5-1.0.1.jar
       openjpa-jdbc-1.0.1.jar
        openjpa-kernel-1.0.1.jar
         openjpa-lib-1.0.1.jar
          commons-collections-3.2.jar
          commons-lang-2.1.jar
          serp-1.13.1.jar
      openjpa-persistence-1.0.1.jar (optional)
       openjpa-kernel-5-1.0.1.jar
        openjpa-lib-5-1.0.1.jar
     swizzle-stream-1.0.1.jar
     wsdl4j-1.6.1.jar
     xbean-finder-3.3-SNAPSHOT.jar
     xbean-naming-3.3-SNAPSHOT.jar
     xbean-reflect-3.3-SNAPSHOT.jar

This list is generated at build time and packed in the jar in txt and  
xml format.  We just need to find a few places to catch  
NoClassDefFoundErrors and ClassNotFoundExceptions and print the list  
out in the error message.  Hope that will help cut the trial and error  
down when starting with just the openejb-core jar.

I'm also working on a way to cut this list in half by creating some  
"all-in-one" jars to group together sets of related jars into one jar.

Seems like these things should be a big help to you.  If you have any  
ideas yourself on how we can slick things up to cut your "messing with  
openejb" time down, we're all ears.  Very good chance you'll see some  
quick turnaround on any ideas you have.

Thanks again!

-David