1 Reply Latest reply on Feb 11, 2008 2:49 AM by Luca Ferrari

    error reloading a class

    Luca Ferrari Newbie

      Hi all,
      I'm writing a custom class loader that exploits Javassist to manipulate classes on the fly. This is what I'd like to do:
      1) start with a clear class (not manipulated) loaded from the root custom classloader
      2) manipulate the class inserting an interface on it, load the class with a custom classloader child of the root one
      3) cast the new instance to the added interface
      4) reload the class without the interface with a third loader, child of the root one

      Now, steps from 1-3 works, but I'm not able to remove the interface. Or better, if I reload the class without the interface and try to cast it to the interface I success. The problem seems that after step 2 the class is frozen to the one with the interface and its definition is not allowed. I've tried to defrost the class, but it does not work. Please note that the clean class is firstly loaded without any manipulation, in order to provide a clean in memory image of the class.

      Any suggestion?

        • 1. Re: error reloading a class
          Luca Ferrari Newbie

          Just to make it clearer:
          * the interface I'm going to apply will remain the same during the whole program, and so I guess it can be loaded by a parent (even root) loader;
          * the class to which the interface will be applied can change during the program execution, and so should be loaded by a custom classloader.

          The actual hierarchy of the loaders is:

          root (loads the interface to add)
          | \
          | \
          | custom_add (loads the class with the interface)
          custom_remove (loads the class without the added interface)

          So my question is: why the addition can work and the removal not? I mean, after the class has been reloaded by custom_add, I can cast the class to the added interface, while after reloading it with custom_remove I _can still_ cast it to the interface.