[
http://issues.ops4j.org/browse/QI-230?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13211#action_13211
]
Niclas Hedhman commented on QI-230:
-----------------------------------
Ok, I managed to recreate the problem...
Below is a working TestCase, i.e. the problem is NOT triggered. But by removing
the comment and commenting the line below the comment, i.e. moving the "Other"
declaration from statically on the Some service to dynamically at bootstrap,
the problem manifests itself.
{code:java}
package org.qi4j.runtime.bootstrap;
import static org.junit.Assert.*;
import org.junit.Test;
import org.qi4j.api.Qi4j;
import org.qi4j.api.composite.Composite;
import org.qi4j.api.concern.ConcernOf;
import org.qi4j.api.concern.Concerns;
import org.qi4j.api.injection.scope.Service;
import org.qi4j.api.injection.scope.Structure;
import org.qi4j.api.injection.scope.This;
import org.qi4j.api.mixin.Mixins;
import org.qi4j.api.mixin.NoopMixin;
import org.qi4j.api.service.ServiceComposite;
import org.qi4j.bootstrap.AssemblyException;
import org.qi4j.bootstrap.ModuleAssembly;
import org.qi4j.test.AbstractQi4jTest;
public class DereferenceForBootstrappedConcernsTest
extends AbstractQi4jTest
{
public void assemble( ModuleAssembly module )
throws AssemblyException
{
// module.addServices( Some.class ).withMixins( NoopMixin.class
).withConcerns( OtherConcern.class );
module.addServices( Some.class );
module.addServices( Result.class );
}
@Test
public void whenDerefencingInsideConcernThisExpectItToWork()
throws Exception
{
Result result = (Result) serviceLocator.findService( Result.class
).get();
Some some = (Some) serviceLocator.findService( Some.class ).get();
assertEquals( "method()", some.method() );
assertEquals( some.identity(), result.some().identity() );
assertEquals( some.identity().get(), result.some().identity().get() );
}
@Mixins( ResultMixin.class )
public interface Result
extends ServiceComposite
{
void execute( Some value );
Some some();
}
public static abstract class ResultMixin
implements Result
{
private Some value;
public void execute( Some value )
{
this.value = value;
}
public Some some()
{
return value;
}
}
@Concerns( OtherConcern.class )
@Mixins( NoopMixin.class )
public interface Other
{
void other();
}
@Mixins( SomeMixin.class )
public interface Some
// extends ServiceComposite
extends ServiceComposite, Other
{
String method();
}
public abstract static class SomeMixin
implements Some
{
@This
private Other other;
public String method()
{
other.other();
return "method()";
}
}
public static class OtherConcern
extends ConcernOf<Other>
implements Other
{
@Structure
private Qi4j api;
@This
private Composite me;
@Service
private Result result;
public void other()
{
Composite value = api.dereference( me );
result.execute( (Some) value );
next.other();
}
}
}
{code}
> Qi4j.dereference() does not work inside Concerns/SideEffects, if Concern
> added withConcerns() in bootstrap.
> -----------------------------------------------------------------------------------------------------------
>
> Key: QI-230
> URL: http://issues.ops4j.org/browse/QI-230
> Project: Qi4j
> Issue Type: Bug
> Reporter: Niclas Hedhman
> Assignee: Rickard Öberg
>
> If I add a Concern with ServiceDeclaration.withConcerns() and dereferences
> the Composite pointer inside that Concern with Qi4j.dereference(), then a
> ClassCastException happens on the following line;
> class Qi4jRuntimeImpl
> {code:java}
> public <T> T dereference( T composite )
> {
> InvocationHandler handler = getInvocationHandler( composite );
> if( handler instanceof ProxyReferenceInvocationHandler )
> {
> return (T) ( (ProxyReferenceInvocationHandler) handler ).proxy();
> <--- HERE
> }
> if( handler instanceof CompositeInstance )
> {
> return composite;
> }
> return null;
> }
> {code}
> Because the ProxyReferenceInvocationHandler.proxy is not a Composite, but a
> $Proxy that can not be cast to a Composite.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.ops4j.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev