Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] A pointcut to match all static methods in a class with some restrictions

Thanks Andy,

I think I get the point here. One thing I forgot to mention is that when I do this with LTW the warnings keep coming for a minute or so and then comes the dreaded OutOfMemory: Java Heap Space exception. So in some sense it's not really working how I want ;-) Should printing error messages really consume this much memory? This might be a problem for me because I'm working on an automatic code generator that generates these aspects, and the more detail I have to put in the generator, the more of a pain it will be to keep correct, and I expect that more detailed the pointcut description is, the more runtime checks they need?!

Jochen



On Mar 13, 2009, at 9:06 PM, Andy Clement wrote:

So everything is working as you want, you just want to know about the warnings.

> [AppClassLoader@517590db] warning at javax/servlet/jsp/aspects/ Users/joe/Documents/uni/research/LuMi/workspace/tomcat6.0.9 > _aspects/src/javax/servlet/jsp/aspects/JspFactory_Initialized.aj: 31::0 does not match because declaring type is java.lang.Object, > if match desired use target(javax.servlet.jsp.JspFactory) [Xlint:unmatchedSuperTypeInCall]
> see also: org/apache/catalina/connector/Connector.java:1013::0

Suppose the toString() method is called on a JspFactory, or hashCode() - those are methods inherited from Object, perhaps not implemented by your JspFactory. Should call(* JspFactory.*(..)) match calls to them? well JspFactory doesn't define them, so no. And just in case you really wanted to include them but accidentally used the declaring type inappropriately in call(), there is a warning from the compiler.

The warning is telling you the declaring type of the method involved is Object and if you want a match, you will need to use target, if you don't want a match then it doesn't matter and you can ignore it (turn off the warning if you like, it is an xlint).

Here is a trivial case:
-- A.java --
public class A {
  public void foo() {
    int i = hashCode();
  }
}

aspect X {
  before(): call(* A.*(..)) {}
}
---
C:\aspectj164-dev>ajc A.java
C:\aspectj164-dev\A.java:8 [warning] does not match because declaring type is java.lang.Object, if match desired use target(A) [Xlint:unmatchedSuperTypeInCall]
before(): call(* A.*(..)) {}
          ^^^^^^^^^^^^
        [Xlint:unmatchedSuperTypeInCall]
        see also: C:\aspectj164-dev\A.java:3::0

1 warning

Doesn't matter for static methods. And target can be used to match non-static methods:
--- A.java ---
public class A {
  void foo() {
  }

  static void goo() {
  }

}

aspect X {
  before(): execution(* *(..)) && !target(Object) {}
}
---
C:\aspectj164-dev>ajc A.java -showWeaveInfo
Join point 'method-execution(void A.goo())' in Type 'A' (A.java:5) advised by before advice from 'X' (A.java:11)

if target is not a derivative of Object then it must be a static method. But qualifying it in your pointcut is a more optimal way to express it.


Andy





Back to the top