Hello there!

I have just found out something that really scared me!
I am using for this example 2 Decorators for one Interface and a simple implementation, like this:

interface Service extends Serializable{
  public Object getSomething(int value);
  public boolean test(String text);
}

-----------------
public class MyService implements Service {

  /* Used somewhere else to be able to use decorators and interceptors */
  @Inject
  private Service delegate;

  public boolean test(String text){
    return false;
  }
}

-----------------
@Decorator
public abstract class ServiceDecoratorA implements Service {
  @Delegate
  @Inject
  private Service delegate;

  public boolean test(String text){
    Object o = delegate.getSomething();

    if(/*condition*/){
      return true;
    } else {
      return delegate.test(text);
    }
  }
}

----------------
@Decorator
public abstract class ServiceDecoratorB implements Service {
  @Delegate
  @Inject
  private Service delegate;

  public boolean test(String text){
    Object o = delegate.getSomething();

    if(/*condition*/){
      return true;
    } else {
      return delegate.test(text);
    }
  }
}

Invocation(Through EL): #{myService.test('aString')}
Expected Invocation-Chain: OWB-Proxy.test(String)->...->ServiceDecoratorA.test(String)->ServiceDecoratorB.test(String)->MyService.test(String) Actual Invocation-Chain: OWB-Proxy.test(String)->...->ServiceDecoratorA.test(String)->MyService.test(String)

When I call the method test(String) decorator A is accessed when the condition evaluates to false I would expect the next decorator to be called, instead MyService.test(String) is called. If I put the expression delegate.test(String) to the first line in the decorator method, temporary put the result in a local var and return the local vars content, everything works as expected.

I think that the invocation of the delegate mixes up a state of the OWB proxy or so. I have no idea about what happens here but it sucks and I think that this behavior is wrong. I fixed this problem right now with temporary saving the delegates return into a local var and the do other invocations on the delegate.

Is this a bug or is it not allowed to call other methods than the decorated one in the decorator method?

Regards,

Christian

Reply via email to