Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Preventing Reflection

This will not work since the target is the object of type java.lang.reflex.*.
Try the following, you will see,

public privileged aspect BlockReflection
{
  pointcut captureReflection(): call(* java.lang.reflect..*.*(..));
  before() : captureReflection()
  {
    System.out.println("target type: " + thisJoinPoint.getTarget().getClass());
  }
}

You may also want have a look at 
http://www.eclipse.org/aspectj/doc/released/faq.php#q:reflectiveCalls.

--
Dehua Zhang
Sable Research Group, McGill University
Montréal, Québec, Canada
http://www.cs.mcgill.ca/~dzhang25





-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx on behalf of Rob Austin
Sent: Sun 1/13/2008 10:17
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] Preventing Reflection
 
Hi,

Can you tell me if it's possible to catch reflection on a specific class,
and where reflection does occur get a handle on the target object?

Something like this, except that this doesn't work:

public privileged aspect BlockReflection
{

 pointcut captureReflection(apoptotic.bookTrading.BookSellerAgent seller):
call(* java.lang.reflect..*.*(..))  && target(seller);
  before(apoptotic.bookTrading.BookSellerAgent seller) :
captureReflection(seller)
  {
      // call a method on the object which was targetted by reflection
       seller.takeDown();
  }

}


Really appreciate it.

Rob



Back to the top