This discussion is archived
3 Replies Latest reply: Jul 25, 2010 3:13 AM by EJP RSS

Super/sub-types loaded with different classloaders

843798 Newbie
Currently Being Moderated
Hi,

I have a use case where
- My client has a SampleBO to which he sets various values
- Needs to extend this SampleBO to ExtendedSampleBO object that provides additional functionality.
- ExtendedSampleBO is a class that is not present in the client application, but the client can request the framework to downloaded and load it - USING A SEPARATE CLASSLOADER - from binary files stored in the database.
( SampleBO is present in the client side and loaded by the normal application classloader )

My problem is that after I get an ExtendedSampleBO object, if I try to access the methods of the super-type (SampleBO), I get IllegalAccessError. How do I solve this problem??!!

Re-stating my requirement - Client needs to set some values in a BO. The framework has to provides a mechanism for dynamically extending the functionality of the BO by using binary files deployed to the database.

Please help!!!
Zeba
  • 1. Re: Super/sub-types loaded with different classloaders
    843798 Newbie
    Currently Being Moderated
    public class IllegalAccessError
    extends IncompatibleClassChangeError

    Thrown if an application attempts to access or modify a field, or to call a method that it does not have access to.

    Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.
    The SampleBO class that your client referenced when compiling ExtendedSampleBO
    does not match the SampleBO class you are using at runtime.
  • 2. Re: Super/sub-types loaded with different classloaders
    843798 Newbie
    Currently Being Moderated
    Actually problem was that the special `ClassLoader` that loads `ExtendedSampleBO` is not a child of the `ClassLoader` that loaded `SampleBO`. Hence the `ClassLoader` of 'ExtendedSampleBO' was creating its own `SampleBO` class and that was different from the application's `SampleBO` class.

    Actually the application has a large number of Rule-set's (binary files), each of which is loaded from db by its own classloader. However, all of these Rule-sets have a common Master ( also loaded from db by a separate classloader ). So instead of loading the Master binary files from the db for each of the Child-set's, I just save a reference to the master class-loader and use that within the Rule-set's class-loaders to load the files ( to save memory by avoiding same classes being loaded multiple times over multiple classloaders - there will be a large number of Rule-set's).

    Anyone knows of any other solution than making the Master classloader a child of the Rule-set classloader??

    Thanks!
    Zeba
  • 3. Re: Super/sub-types loaded with different classloaders
    EJP Guru
    Currently Being Moderated
    No, why do you need another solution?