Rickard,

I don't understand how the CGLib enhanced subclasses with pointer back
to the original class can actually work.

The key (I think) lies in the MixinModel and following code;

    public Object newInstance( CompositeInstance compositeInstance,
StateHolder state, UsesInstance uses )
    {
        InjectionContext injectionContext = new InjectionContext(
compositeInstance, uses, state );
        Object mixin;
        try
        {
            if( Factory.class.isAssignableFrom( instantiationClass ) )
            {
                Enhancer.registerCallbacks( instantiationClass,
                                            new Callback[]{
                                                new
ThisCompositeInvoker( compositeInstance ), NoOp.INSTANCE
                                            } );
            }

When the Enhancer.registerCallbacks() is called, CGLib basically do;

            Method setter = getCallbacksSetter(type, methodName);
            setter.invoke(null, new Object[]{ callbacks });

which is a STATIC method call to the generated class for setting the
the callback implementations.

BUT, the callback depends on having the pointer to the ACTUAL instance
of the class.

Hence, from my simple perspective, it appears that this code would
actually only work if there is a single instance of such type, OR if
there is one instantiationClass generated per instance used (can't
possibly be!).


Am I on to something here, or have I missed something completely??

Since you are currently in the air, I'll try to create a testcase to
verify my suspicion.


Cheers
-- 
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java

I  live here; http://tinyurl.com/2qq9er
I  work here; http://tinyurl.com/2ymelc
I relax here; http://tinyurl.com/2cgsug

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to