Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Weaving into more classes than it should?

Aha! That's exactly what I was looking for. I wasn't understanding why AspectJ was trying to weave into different classes when I had specified a target() but I had it wrong; it's indeed within() I was looking for. Thanks also for the tip with the fully classified names. I'm using them to prevent any issues with ambiguity but now that you mention it, if I have the import down to the package where the class is, it shouldn't be a problem.

Thanks for all the help!

Tiago

On Wed, Feb 16, 2011 at 5:28 PM, Simone Gianni <simoneg@xxxxxxxxxx> wrote:
Hi Tiago,
in your pointcut you used "target" :

execution(public void com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletContext HttpServletRequest, HttpServletResponse))
&& target(com.sun.xml.ws.transport.http.servlet.ServletAdapter);

> Am I missing something stupidly obvious in AspectJ? I thought whenever
> I weaved an aspect with the "execution()" pointcut, I would just be
> touching the target class; so if that's the case, why is ajc trying to
> weave into other random classes?

By default, execution pointcut will match also all subclasses, that's why AspectJ is examining all classes to see if they extend ServletAdapter (as Andy already pointed out). If you don't need this, but want to only weave into ServletAdapter, maybe you should use "within" instead of "target".

execution(public void com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletContext, HttpServletRequest, HttpServletResponse))
&& within(com.sun.xml.ws.transport.http.servlet.ServletAdapter);

In this case, AspectJ will quickly determine that subclasses are not to be weaved, and avoid exploring all the superclasses to see if they match the execution pointcut.

That should get rid of the error messages (which are in this case useless, but from time to time you could really benefit from them while writing other aspects), speed up things, and avoid to weave subclasses if you don't need to.

BTW : you can add and import for ServletAdapter, and avoid using fully classified names in pointcuts. 

Hope this helps,
Simone 

2011/2/8 Tiago Espinha <tiago@xxxxxxxxxx>

Hi Andy,

That makes sense with the error message. I've also tried with the
-Xlint:ignore switch and it worked! (and indeed, I'm pretty sure those
classes shouldn't be touched)

Thank you very much!

Cheers,
Tiago

On Tue, Feb 8, 2011 at 3:51 PM, Andy Clement <andrew.clement@xxxxxxxxx> wrote:
> Hi,
>
> The message is unfortunately a bit misleading, it says:
>
>> ---------------------8<-------------------------------
>> C:\glassfishv3\glassfish\modules\webservices-osgi.jar [error] can't
>> determine superclass of missing type org.apache.tools.ant.Task
>> when weaving type com.sun.xml.ws.installer.UpdateSharedLoaderProp
>> when weaving classes
>> when weaving
>> when batch building BuildConfig[null] #Files=1 AopXmls=#0
>>  [Xlint:cantFindType]
>> (no source information available)
>>        [Xlint:cantFindType]
>> ---------------------8<-------------------------------
>
> But what it means instead of 'when weaving' is 'when matching and
> possibly weaving'.  It means it is performing analysis on some types
> to see if they might match (maybe they subclass ServletAdapter)  - it
> can't see the entire supertype chain because a superclass is missing.
> Now, these messages are Xlint, so they can be turned off if you are
> confident that you don't care about those missing types.  The option
> -Xlint:ignore will switch them off.
>
> Andy
>
>
> On 8 February 2011 02:59, Tiago Espinha <tiago@xxxxxxxxxx> wrote:
>> Hi all,
>>
>> I have a JAR that comes with GlassFish (webservices-osgi.jar) and
>> within this jar, there's a class by the name of
>> com.sun.xml.ws.transport.http.servlet.ServletAdapter.
>>
>> What I'm trying to do is to capture all executions of the method
>> handle() within this class, so that means ServletAdapter.handle(...).
>>
>> The thing is, I have the following aspect (which I've tried to strip
>> to barebones):
>> ---------------------8<-------------------------------
>> import java.io.BufferedReader;
>> import java.io.InputStreamReader;
>> import java.io.OutputStreamWriter;
>> import java.net.URL;
>> import java.net.URLConnection;
>> import java.net.URLEncoder;
>> import java.util.Calendar;
>>
>> import javax.servlet.ServletContext;
>> import javax.servlet.http.HttpServletRequest;
>> import javax.servlet.http.HttpServletResponse;
>>
>> public aspect SoapAspect {
>>        pointcut handlerInvoked() :
>>                 execution(public void
>> com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletContext,
>> HttpServletRequest, HttpServletResponse))
>>                 && target(com.sun.xml.ws.transport.http.servlet.ServletAdapter);
>>           before() : handlerInvoked()
>>           {
>>                //(...)
>>           }
>> }
>> ---------------------8<-------------------------------
>>
>> And whenever I try to weave this simple aspect into the JAR, I get a
>> few dozen errors about it not being able to determine the supertype of
>> classes that aren't even related to the class I'm weaving. Here's an
>> example of one of such errors (there's 34 in total):
>> ---------------------8<-------------------------------
>> C:\glassfishv3\glassfish\modules\webservices-osgi.jar [error] can't
>> determine superclass of missing type org.apache.tools.ant.Task
>> when weaving type com.sun.xml.ws.installer.UpdateSharedLoaderProp
>> when weaving classes
>> when weaving
>> when batch building BuildConfig[null] #Files=1 AopXmls=#0
>>  [Xlint:cantFindType]
>> (no source information available)
>>        [Xlint:cantFindType]
>> ---------------------8<-------------------------------
>>
>> You can have a look at the ServletAdapter class here
>> (http://www.docjar.com/html/api/com/sun/xml/ws/transport/http/servlet/ServletAdapter.java.html)
>> and see that there's no reference whatsoever to either Task or
>> UpdateSharedLoaderProp.
>>
>> Am I missing something stupidly obvious in AspectJ? I thought whenever
>> I weaved an aspect with the "execution()" pointcut, I would just be
>> touching the target class; so if that's the case, why is ajc trying to
>> weave into other random classes?
>>
>> Thanks in advance!
>>
>> Tiago
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top