Bug 349961 - compilation ordering issue for parameter annotation matching
Summary: compilation ordering issue for parameter annotation matching
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-21 11:58 EDT by Andrew Clement CLA
Modified: 2013-06-24 11:05 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Clement CLA 2011-06-21 11:58:15 EDT
From the mailing list: 
I found a workaround and wrote a unit test that runs on developer machines but not on the build server !

The problem occurs with parameter annotations on an local interface :

The parameter annotation :

 package com.example;

 import java.lang.annotation.ElementType;
 import java.lang.annotation.Inherited;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;

 @Inherited
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.PARAMETER)
 public @interface MyParameterAnnotation {
 }


The local interface :

 package com.example;

 import javax.ejb.Local;

 @Local
 interface A {
     public String a(@MyParameterAnnotation String s);
 }


The implementation bean :

 package com.example;

 import javax.ejb.Stateless;

 @Stateless
 class ABean implements A {
     public String a(String s) {
         return s;
     }
 }


The aspect :

 package com.example;

 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Pointcut;

 @Aspect
 public class MyAspect {

     @Pointcut("execution(* *(..,@MyParameterAnnotation (String),..))")
     public void anyMethodCallWithMyParameterAnnotation() {
     }

     @Around("anyMethodCallWithMyParameterAnnotation()")
     public Object aroundMethodWithMyParameterAnnotation(ProceedingJoinPoint pjp) throws Throwable {
         throw new RuntimeException("OK");
     }
 }


The unit test :

 package com.example;

 import org.junit.Assert;
 import org.junit.Test;

 public class MyAspectTest {

     @Test
     public void testIt() {
         A a = new ABean();
         try {
             Assert.assertEquals("aha", a.a("aha"));
             Assert.fail("Failed due to a weaving problem.");
         }
         catch (Exception e) {
             Assert.assertEquals("OK", e.getMessage());
         }
     }
 }

This test can be "fixed" when you add the @MyParameterAnnotation annotation on the parameter of the implementation bean too.

Regards,

Diether
Comment 1 Andrew Clement CLA 2011-06-21 16:13:26 EDT
fixed
Comment 2 Andrew Clement CLA 2013-06-24 11:05:22 EDT
unsetting the target field which is currently set for something already released