katentim (2) [Avatar] Offline
#1
I'm trying to do policy enforcement to check for unsafe thread usage of some objects. I'd like to declare an error for usage of HttpServletRequest under Runnable.run.

I've tried:

public aspect NoRequestCallsInNewThreads {
pointcut requestCalls() : call (* javax.servlet.http.HttpServletRequest.*(..));

declare error : requestCalls() && threadedCalls()
: "Request calls not allowed in new threads";

pointcut threadedCalls() : cflow (call(* Runnable.run()));

}


but I get:
"cflow() pointcut designator cannot be used in declare statement"
in Eclipse. Can this be done? If so how?
ramnivas (171) [Avatar] Offline
#2
Re: Threadsafe Usage - cflow and declare error
Since "declare error" affects the compile time behavior, it must use a compile-time determinable pointcut. Since the cflow() depends on runtime control-flow, it cannot be determined at compile-time you may not use such a pointcut in "declare error".

Instead, you may want to use an advice to log the invalid access (and unless you are weaving into your web container, you will need to use execution() instead of call(), assuming you are weaving into the servlet).

I hope this helps.

-Ramnivas
katentim (2) [Avatar] Offline
#3
Re: Threadsafe Usage - cflow and declare error
That makes sense - thanks for the quick reply.

PS - Excellent book BTW smilie