Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] A gap between compile-time Join point matching and runtime reflection

You are in an area where there is a known bug that affects pointcut
matching with annotations, i think your situation is a similar-ish
case that should be checked at the same time.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=128664

Your pointcut "call(* (@Marker *).*(..))" matches the
serviceImpl.doService() call because the signatures of that joinpoint
are considered to be:
1. ServiceImpl.doService()
2. Service.doService()

and in the latter case the type is annotated and you match.  The
annotation is not accessible because:
1. you haven't said the annotation is @Inherited
and
2. even if you did, annotations are not inherited from interfaces

basically it is a bit of a mismatch between join point signatures and
annotation inheritance that we need to sort out - either by supplying
better documentation of how/why it works...or changing the behaviour.

Andy.


On 18/04/06, Eiichiro Uchiumi <eiichirouchiumi@xxxxxxxxxxx> wrote:
> Hi, All
>
> I have a question about this subject. Please check following code.
> =================================================================
>
> @Target(ElementType.TYPE)
> @Retention(RetentionPolicy.RUNTIME)
> public @interface Marker {
>  // Marker annotation
> }
>
> -----------------------------------------------------------------
>
> @Marker
> public interface Service {
>  public void doService();
> }
>
> -----------------------------------------------------------------
>
> public class ServiceImpl implements Service {
>  public void doService() {
>  }
> }
>
> -----------------------------------------------------------------
>
> public class Client {
>
>  private Service service = new ServiceImpl();
>
>  private ServiceImpl serviceImpl = new ServiceImpl();
>
>  public void useService() {
>   service.doService();  // Match! -> "Match-A"
>   serviceImpl.doService(); // Match! -> "Match-B"
>  }
>
> }
>
> -----------------------------------------------------------------
>
> @Aspect
> public class AnAspect {
>
>  @Around("call(* (@Maker *).*(..))")
>  public Object doAdvice(ProceedingJoinPoint pjp) throws Throwable {
>
>   pjp.getSignature().getDeclaringType().getAnnotation(Maker.class);
>
>   // ...
>  }
>
> }
>
> When specified Joint point is "Match-A",
> pjp.getSignature().getDeclaringType().getAnnotation(Maker.class) returns
> Maker annotation, but specified Joint point is "Match-B",
> it returns null...
> Though this pointcut expression matches both of join point, I cannot get
> the same annotation with runtime reflection.
> Why this pointcut expression matches both of join point?
> Is it the AspectJ 5 specification?
>
> (I use AspectJ 1.5.1a with AJDT 1.4.0.20060413082832 on
> Eclipse 3.2M6)
>
> Thanx!
> Eiichiro UCHIUMI (Tokyo/Japan)
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top