Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] pointcut to detect String concatenation at invocation of Log4j?

Philip,

You could do this in some cases with two pieces of advice: one that detects calls to string append (i.e., the + operator translates into a call in bytecode) and sets local state for the line number and class on which it occurred (using thisJoinPoint and stored in, e.g., a ThreadLocal), and another with a pointcut for log calls, which will check if the line number and class is the same as the last string concatenation.

But relying on the same line number gives false positives and negatives:

logger.info("foo"); x="foo"+"bar"; // false positive
logger.info(        // I believe the line number of the append call will
      "ace" +       // differ from that of the info call
      "baz"
   );

This approach also will match calls that are already properly guarded:
> 	if (logger.isEnabledFor(Level.DEBUG))
> 	{
> 		logger.debug("Problem with op:" + obj);
> 	}

What would be nice is a join point for the start of argument evaluation for a method. If you had it you could use cflow to check your case (or use thisEnclosingJoinPointStaticPart). However, I don't think is possible to implement a pointcut for this proposed join point in a bytecode weaving implementation as AspectJ has been since 1.1 (because optimizations can move the order of execution). 

Ron Bodkin
Chief Technology Officer
New Aspects of Software
o: (415) 824-4690
m: (415) 509-2895


> ------------Original Message------------
> From: "Lee, Philip" <Philip.Lee@xxxxxxxxxxxxx>
> To: "'aspectj-users@xxxxxxxxxxx'" <aspectj-users@xxxxxxxxxxx>
> Date: Thu, Nov-4-2004 7:32 AM
> Subject: [aspectj-users] pointcut to detect String concatenation at invocation of Log4j?
>
> Hi,
> 
> I'm trying to formulate a run time check that catches any unprotected 
> calls
> to Log4j that incur the cost of string concatentation
> 
> e.g. I want to catch the following and print the line number of the
> invocation
> 
> 	logger.Debug("Problem with op:" + obj);
> 
> so that it can be changed to
> 
> 	if (logger.isEnabledFor(Level.DEBUG))
> 	{
> 		logger.Debug("Problem with op:" + obj);
> 	}
> 
> Is it possible to specify "string concatenation at point of function 
> call"?
> 
> TIA,
> 
> 	Phil.
> 
> 
> 
> This e-mail and any attachment is for authorised use by the intended 
> recipient(s) only. It may contain proprietary material, confidential 
> information and/or be subject to legal privilege. It should not be copied, 
> disclosed to, retained or used by, any other party. If you are not an 
> intended recipient then please promptly delete this e-mail and any 
> attachment and all copies and inform the sender. Thank you.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 
> 



Back to the top