[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] pointcut to intercept "instanceof" instruction ?


I'm afraid there is no join point exposed for instanceof tests, so you cannot write a pointcut to pick them out in the code.  Adding support for this is something that has come up in the past but not many use cases have been put forward, so it hasn't been implemented.  Actually I don't think we are actually tracking an enhancement to add this feature - feel free to raise one and add your use case.


2008/7/24 nicolas de loof <nicolas@xxxxxxxxxx>:


I'd like to define an Aspect to detect use of "instanceOf" instruction in my business domain code.
As I'm using Hibernate, the abstract @Entity class "Pet" cannot be casted to its child "Cat" due to Hibernate proxies :

Pet felix = ....;
if (felix instanceOf Cat) { // will always be false
    Cat cat = (Cat) felix;  // will fail anyway

To avoid such error in code, I'd like to create an aspect to detect use of instanceOf with a class that is annotated with @Entity.

As I'm not an aspectJ pointcut _expression_ guru, I'd welcome any help ;-)

aspectj-users mailing list