Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] pointcut does not match private static method

However, I think your solution might match more than wanted. It will match
all methods whose class implements DAOCenterContainer and not only classes
under se.stickybit.licensetracker.server. Can I combine the two?

Sure, just use "&&" e.g.

    pointcut TRANSACTIONAL(Transactional transactionalAnnotation):
        execution(@Transactional * se.stickybit.licensetracker.server..*(..)) 
               && execution(* DaoConterContainer+.*(..))
        && @annotation(transactionalAnnotation);

Also, the + notation/operator is not mentioned in the reference. Not sure
whether you are an AspectJ developer, but if you are it would be useful to
have list of the different operators such as *, +, ! etc.

Type pattern operators (such as "+") are documented here:


"can't throw checked exception
'se.stickybit.licensetracker.server.exceptions.StorageException' at this
join point 'method-execution(void
se.stickybit.licensetracker.server.Server.checkLicense(se.stickybit.licensetracker.server.dao.DAOCenter))'"

This message means that your *advice* cannot throw a StorageException, because the method signature does not declare that a StorageException can be thrown as a result of executing the method. You haven't posted your advice body, but it looks like the advice you have associated with the pointcut _expression_ must throw this exception. 

Regards, Adrian.


On 3 Nov 2006, at 10:59, Jimisola Laursen wrote:


Of course! Now when I read your post it is so obvious. Let's forget about
that :)

However, I think your solution might match more than wanted. It will match
all methods whose class implements DAOCenterContainer and not only classes
under se.stickybit.licensetracker.server. Can I combine the two?
Looking at the AspectJ 5 Quick Reference I believe that I could use
withincode, but I am not sure.
Also, the + notation/operator is not mentioned in the reference. Not sure
whether you are an AspectJ developer, but if you are it would be useful to
have list of the different operators such as *, +, ! etc.

I partially solved the issue by making the method non-static instead.
Instead I get the following exception:

"can't throw checked exception
'se.stickybit.licensetracker.server.exceptions.StorageException' at this
join point 'method-execution(void
se.stickybit.licensetracker.server.Server.checkLicense(se.stickybit.licensetracker.server.dao.DAOCenter))'"

but no StorageException is thrown. I am a 100% sure. One line in that method
throws a StorageException, but that is catch and boxed in another exception
class. That is:

    @Transactional(level = TRANSACTION_LEVEL.READ_COMMITTED)
    private void checkLicense(final DAOCenter daoCenter) throws
InvalidLicenseException
    {
        try
        {

            Map<Integer, AgentBean> agents =
daoCenter.getAgentDAO().getAgents(qp).getResults();
            numberOfAgents = agents.size();
        }
        catch (final StorageException ex)
        {
            throw new InvalidLicenseException("Unable to lookup number of
agents in system", ex);
        }

        ....
    }

if I wrap all of the code in the method in a try-catch that catches
StorageException I get:

"Unreachable catch block for StorageException. This exception is never
thrown from the try statement body"

One workaround is to add StorageException to the throws list but it is not a
good-enough solution since this method is only allowed to throw
InvalidLicenseException.

Any ideas or might this be a bug?

Regards,
Jimisola



Adrian Colyer-2 wrote:

The pointcut doesn't match the static method execution because of  
this component:

        && this(DAOCenterContainer);

which matches a join point if (there is an object bound to 'this'  
and) the object bound to 'this' is an instance of DAOCenterContainer.
For a static method execution join point, there is no object bound to  
this and so the pointcut does not match.

Try using this variation instead:

    pointcut TRANSACTIONAL(Transactional transactionalAnnotation):
        execution(@Transactional * DAOCenterContainer+.*(..))
        && @annotation(transactionalAnnotation);

which will match based on the types in which the executing operations  
are defined (DAOCenterContainer or any subtype thereof) rather than  
on runtime types.

-- Adrian



On 3 Nov 2006, at 09:57, Jimisola Laursen wrote:


(this might trivial, but I am not AspectJ guru - yet)

Hi!

I have a problem with the following pointcut


    pointcut TRANSACTIONAL(Transactional transactionalAnnotation):
        execution(@Transactional *
se.stickybit.licensetracker.server..*(..))
        && @annotation(transactionalAnnotation)
        && this(DAOCenterContainer);

only matching public non-static methods under
"se.stickybit.licensetracker.server..*".

The following method e.g. is not matched when it is private static

    @Transactional(level = TRANSACTION_LEVEL.READ_COMMITTED)
    private static void checkLicense(final DAOCenter daoCenter) throws
InvalidLicenseException


if I change it to public void checkLicense then it matches.

Doesn't pointcut match non-static methods per default?

I want my around advice to handle all methods regardless of  
"member" access
and static/non-static.
Do I need to have two pointcuts? And apply the advice on both?

I tried:

    pointcut TRANSACTIONAL(Transactional transactionalAnnotation):
        execution(@Transactional private static *
se.stickybit.licensetracker.server..*(..))
        && @annotation(transactionalAnnotation)
        && this(DAOCenterContainer);

without any luck.


Regards,
Jimisola

PS. Is there a IRC channel for aspectj? I looked around and  
couldn't find
one. I think it would be very useful for the community.  DS.

-- 
View this message in context: http://www.nabble.com/pointcut-does- 
not-match-private-static-method-tf2566990.html#a7154770
Sent from the AspectJ - users mailing list archive at Nabble.com.

_______________________________________________
aspectj-users mailing list


_______________________________________________
aspectj-users mailing list



-- 
Sent from the AspectJ - users mailing list archive at Nabble.com.

_______________________________________________
aspectj-users mailing list


Back to the top