Skip to main content

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

Hi,

I've been playing a lot with pointcuts that should address static methods (in classes that potentially also have non-static members).
My basic pointcuts looks like this:

    pointcut initMethod():
    	call(* javax.servlet.jsp.JspFactory.setDefaultFactory(..));

	pointcut blockedMethods(): 		 !cflow(initMethod())
		&& !initMethod()
		&& call(* javax.servlet.jsp.JspFactory.*(..))
		&& !call(* java.lang.Object.getClass(..)); ;
		

The method setDefaultFactory is static and correctly addressed by the initMethod() pointcut. In the second pointcut I get a warning on the line

&& call(* javax.servlet.jsp.JspFactory.*(..))

saying that

"does not match because declaring class is java.lang.Object, if match desired user target(....)"

Now obviously I cannot use target() when I'm working with static methods. Further, in a simple test case the advice using the blockedMethods() pointcut gets woven in exactly the places I expect. But when I run it in a larger project with LTW, I get lots of warnings like this one:

[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

What's funny is that the class Connector in this example doesn't even reference JspFactory or any of the methods therein.

Additionally, when I change the offending line in the pointcut to

&& call(static * javax.servlet.jsp.JspFactory.*(..))

then everything works fine.

I have a little trouble interpreting this behavior. I would expect the '*' without the explicit 'static' to cover both, static and non-static methods. Hence I do not understand the warning I get from the static weaver in the first example with the simple test case. Second, I simply don't understand the warnings produced by the load-time weaver. What are they supposed to mean, and how can the pointcut above possibly match anything that is not declared in JspFactory?

Any help or pointers to detailed documentation are greatly appreciated.

Jochen

Back to the top