You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by John Lindwall <JL...@Xifin.com> on 2005/05/20 03:10:17 UTC

Classloader hell -- need help testing protected/package level met hods using cactus

We've been using cactus 1.6 productively for over 6 months, against WebLogic 6.1. We are now starting to have some problems that I believe are related to the classloader heirarchy of WebLogic and I wonder if anyone has any advice.

We had no problems until somebody modified one of the objects under test from having a public constructor to a protected constructor.  Now we get an illegal access exception:

java.lang.IllegalAccessError: try to access method com.mbasys.mars.pricing.PricingCalcs.<init>()V from class com.mbasys.mars.pricing.ServerTestPricingCalcs at ...

The test case is simply constructing the object under test at the line in question:

package com.mbasys.mars.pricing;
...
    protected void setUp() throws Exception
    {
        super.setUp();

        insertCommonDataIntoDatabase("commonly-used.xml");
        insertIntoDatabase("pricing-setup.xml");
        pc = new PricingCalcs();    // <----------- This line bombs !!!!!!!!!!
    }

If I change the PricingCalcs constructor back to public it works fine.  We see this same type of problem with any test that tries to access protected or package level items.

The ServletTestCase implementation is in the same package (com.mbasys.mars.pricing) as the application class under test (PricingCalcs).  I do this intentionally when writing unit tests (as most do) to allow testing of protected and package level methods.  However I don't think that matters in this case, because the test case is loaded by the webapp ClassLoader but the application class is loaded by the EJB ClassLoader (which is the parent classloader of the webapp).

WebLogic has this kind of ClassLoader heirarchy AFAIK:

	WebApp ClassLoader -> EJB ClassLoader -> System ClassLoader

The cactus test cases are deployed to the cactus webapp's WEB-INF/classes dir so we can hot deploy them.  I'd hate to lose that capability.

The application classes are in the EJB ClassLoader's classpath since the EJBs reference the app classes.

I've tried deploying the application classes to cactus webapp's WEB-INF/classes alongside the test cases and it clears up the (IllegalAccessException) issue mentioned above, but creates some new ugly ClassLoader issues ones which I can detail if need be.  Briefly: One issue was that our application looks up a service in JNDI which depends on some appplication classes/interfaces so we got ClassCastExceptions when accessing these objects in the testcases.    I've tried excluding select application classes from the cactus webapp's WEB-INF/classes dir but it just seems to get messier and messier.

Any ideas?