1

What is the format problem with this pointcut?

@Around("execution(* @myPackage.SafetyCritical.*(*))&& @annotation(deny)")

.i forgot to add: exception is "Pointcut is not well-formed: expecting 'name pattern' (last closing bracket before &&)

for an example the pointcut should work with this class:

@SafetyCritical
public class SecureClass
{

    public SecureClass(){

    }
    @Deny
    public void isNotAllowed(){
        System.out.println("This should not happen");

    }

    @Allow
    public void isAllowed(){
        System.out.println("Allowed");

    }

}
nicholas.hauschild
  • 42,483
  • 9
  • 127
  • 120
Acdc RocknRoll
  • 677
  • 5
  • 9
  • 16

2 Answers2

1

EDIT:

I think the pointcut expression you are looking for would be more like this:

@Around("@target(myPackage.SafetyCritical) && @annotation(denyPackage.Deny)")

The @target designator is used to match classes that are marked with the given annoation, and the @annotation designator will filter to the methods annotated with the denyPackage.Deny annotation.

Again, a look through the Spring Documentation regarding AspectJ support would be helpful.

ORIGINAL:

To match on any number of arguments, the parameters definition passed to the execution pointcut designator should be '..'

@Around("execution(* myPackage.SafetyCritical.*(..)) && @annotation(deny)")

The Spring documentation has some examples of using this to denote accepting any number of arguments.

Also, I would venture to guess that that having the '@' symbol in front of your package name is not acceptable. You should remove it.

nicholas.hauschild
  • 42,483
  • 9
  • 127
  • 120
  • Well, parsing exceptions can sometimes point you in the wrong direction. Have you tried the suggestion? – nicholas.hauschild Dec 12 '11 at 12:29
  • yes i have. why did you left the "@" ? SafetyCritical is an annotation – Acdc RocknRoll Dec 12 '11 at 12:30
  • Well, you shouldn't be trying to use an `execution` pointcut designator with an annotation. The `execution` designator is for matching methods, and the `@annotation` designator should be restricting it to the `deny` annotation. Can you give an example of the code you are trying to match with this expression? – nicholas.hauschild Dec 12 '11 at 12:34
0

I've used a pointcut definition like this to match annotated methods:

@Around("execution(@myPackage.SafetyCritical * *(..)) && @annotation(deny)")

The last part @annotation(deny) (like you already know, but some others may not) is to bind the annotation to the advice method argument named "deny".

Edit: As per your update, I was not aware that SafetyCritical was an annotation on the class. I suppose that would be witin the target() goal then:

@Around("execution(* *(..)) && @target(myPackage.SafetyCritical) && @annotation(deny)")
waxwing
  • 18,547
  • 8
  • 66
  • 82