Skip to content

Commit

Permalink
WELD-1513 Handle circular dependency for non-trivial combination of
Browse files Browse the repository at this point in the history
managed beans and producers
  • Loading branch information
mkouba authored and jharting committed Nov 29, 2013
1 parent de440bc commit 140c1ac
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public <S> CreationalContextImpl<S> getCreationalContext(Contextual<S> contextua
return new CreationalContextImpl<S>(contextual, incompleteInstances, dependentInstances, this);
}

public <S> CreationalContextImpl<S> getProducerReceiverCreationalContext(Contextual<S> contextual) {
return new CreationalContextImpl<S>(contextual, incompleteInstances, Collections.synchronizedList(new ArrayList<ContextualInstance<?>>()), null);
}

public <S> S getIncompleteInstance(Contextual<S> bean) {
return incompleteInstances == null ? null : Reflections.<S>cast(incompleteInstances.get(bean));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@
*/
public interface WeldCreationalContext<T> extends org.jboss.weld.construction.api.WeldCreationalContext<T> {

<S> WeldCreationalContext<S> getCreationalContext(Contextual<S> Contextual);
<S> WeldCreationalContext<S> getCreationalContext(Contextual<S> contextual);

/**
* The returned {@link CreationalContext} shares nothing but incomplete instances.
*
* @param contextual
* @return the {@link CreationalContext} for a producer reciever
* @see WELD-1513
*/
<S> WeldCreationalContext<S> getProducerReceiverCreationalContext(Contextual<S> contextual);

<S> S getIncompleteInstance(Contextual<S> bean);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public void dispose(T instance) {

@Override
public T produce(CreationalContext<T> ctx) {
CreationalContext<X> receiverCreationalContext = getBeanManager().createCreationalContext(getDeclaringBean());

CreationalContext<X> receiverCreationalContext = getReceiverCreationalContext(ctx);
Object receiver = getReceiver(ctx, receiverCreationalContext);

try {
Expand All @@ -153,6 +154,14 @@ public T produce(CreationalContext<T> ctx) {
}
}

private CreationalContext<X> getReceiverCreationalContext(CreationalContext<T> ctx) {
if(ctx instanceof WeldCreationalContext) {
return ((WeldCreationalContext<?>)ctx).getProducerReceiverCreationalContext(getDeclaringBean());
} else {
return getBeanManager().createCreationalContext(getDeclaringBean());
}
}

public DisposalMethod<?, ?> getDisposalMethod() {
return disposalMethod;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.BeanArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
@Ignore("WELD-1513")
public class NonTrivialCircularInjectionTest {

@Inject
Expand Down

0 comments on commit 140c1ac

Please sign in to comment.