Bug 108892 - Load Time Weaving problem with Aspect Definition at 2 Levels of Hierarchy
Summary: Load Time Weaving problem with Aspect Definition at 2 Levels of Hierarchy
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 1.5.0RC1   Edit
Assignee: Alexandre Vasseur CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-06 22:05 EDT by Ron Bodkin CLA
Modified: 2005-11-04 02:30 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ron Bodkin CLA 2005-09-06 22:05:34 EDT
I am trying to weave into Tomcat with a system-level aspect (META-INF/aop.xml 
is found in a jar on the system classpath), and also have a Web application 
with an aop.xml properly deployed. When I try to run them both together, only 
the system-level aspects work. If I remove the system-level aspect jar from the 
classpath, the application-level aspects work. What would be a reasonable way 
to isolate this into a test case? If I could package up a simple system.jar and 
app.war file for Tomcat 5.5.9, would that be useful for you to use in debugging 
it? I tried making a simple standalone version with 2 aop.xml files in the same 
app classloader but that works just fine.
Comment 1 Adrian Colyer CLA 2005-09-08 04:18:18 EDT
tagging with M4...
Comment 2 Matthew Webster CLA 2005-09-08 05:48:45 EDT
I'm not quite sure I understand the problem:
1. When you say "weav into Tomcat" do you mean you are weaving Tomcat classes?
2. When you say "system classpath" do you you java.class.path or 
sun.boot.class.path
3. When you day "only the system-level aspects work" do you mean only the 
Tomcat classes are woven?
4. Could you send the aop.xml files? Are you explicity including/excluding 
classes or aspects?
5. Could you use weaver options "-verbose" and/or "-showWeavInfo" and append 
the resulting logs.
Comment 3 Ron Bodkin CLA 2005-09-08 20:01:51 EDT
Hi Matthew,

1) I have added a jar to the CLASSPATH used on start-up of Tomcat (but not the 
bootclasspath). This jar includes a META-INF/aop.xml file. So the aspects in 
the jar will weave into everything loaded from the AppClassLoader down.
2) java.class.path
3) The jar in the CLASSPATH weaves properly into everything in the system. 
Debug information shows that both it and the Web application-level jar are 
being recognized for the Web app, but that only it is affecting the Web app.
4) Here are the aop.xml files below
5) I will post in a follow-up

classpath agent's aop.xml
<!-- FIXME fails when DTD here and call from Ant-->
<!--<!DOCTYPE aspectj PUBLIC-->
<!--    "-//AspectJ//DTD//EN"-->
<!--    "http://www.aspectj.org/dtd/aspectj_1_5_0.dtd">-->
<aspectj>
    <weaver options="-proceedOnError"> <!-- -showWeaveInfo -verbose --> 
        <exclude within="com.crankj..*"/>
        <exclude within="org.eclipse..*"/>
        <exclude within="org.apache.struts.util..*"/>
        <exclude within="org.apache.catalina.core..*"/>
        <exclude within="org.apache.catalina.cluster..*"/>
        <exclude within="org.apache.commons..*"/>
        <exclude within="org.apache.xerces..*"/>
        <exclude within="org.apache.jasper..*"/>
        <exclude within="org.apache.tomcat.util..*"/>
        <exclude within="org.apache.catalina.util..*"/>
        <exclude within="edu.emory..*"/>
        <exclude within="org.apache.juli..*"/>
        <exclude within="org.apache.naming..*"/>
        <exclude within="org.apache.coyote..*"/>
        <exclude within="org.apache.catalina.storeconfig..*"/>
        <exclude within="org.apache.jk..*"/>
        <exclude within="org.apache.webapp..*"/>
        <exclude within="org.apache.log4j..*"/>
        <exclude within="org.springframework..*"/>
        <!-- <exclude within="*..*CGLIB$*"/>
        <exclude within="$Proxy**"/>
        <exclude within="sun.reflect.Generated*"/>
        <exclude within="com.sun.jmx..*"/> -->
    </weaver>
    <aspects>
        <!-- see here nested class with ".", "$" is accepted as well -->
        <aspect name="com.crankj.monitor.ui.ServletRequestMonitor"/>
        <aspect name="com.crankj.monitor.ui.StrutsRequestMonitor"/>
        <aspect name="com.crankj.monitor.resource.JdbcMonitor"/>
        <aspect name="com.crankj.config.CrankjSystemInitializer"/>
    </aspects>
</aspectj>

Web Application aop.xml file:
<aspectj>
	<!--  <weaver options="-proceedOnError -showWeaveInfo -verbose"> -->
	<weaver options="-proceedOnError">  
        <exclude within="com.crankj..*"/>
        <exclude within="org.eclipse..*"/>
        <exclude within="org.apache.commons..*"/>
        <exclude within="org.apache.xerces..*"/>
        <exclude within="org.apache.naming..*"/>
        <exclude within="org.apache.catalina.storeconfig..*"/>
        <exclude within="org.apache.jk..*"/>
        <exclude within="org.apache.webapp..*"/>
        <exclude within="org.apache.log4j..*"/>
        <exclude within="org.springframework..*"/>
	</weaver>
    <aspects>
        <aspect name="com.crankj.aspects.BadSysInfluence"/>
        <aspect name="com.crankj.aspects.BadAppInfluence"/>
    </aspects>
</aspectj>
Comment 4 Matthew Webster CLA 2005-09-09 12:01:35 EDT
You may be encountering a bug with class loaders that I have experienced under 
OSGi (now fixed). Like that environment I presume Tomcat defines it's own. The 
problem lies with ClassLoader.getResources() which the AspectJ weaving adaptor 
uses to find all the available aop.xml files; in your case 2. The bug is that 
it only finds the first one. You can confirm this using the lastest AspectJ 5 
M3, which has lot's of new diagnostic messages, and use "-
Daj.weaving.verbose=true".
Comment 5 Ron Bodkin CLA 2005-09-22 17:19:20 EDT
I found that both the aop.xml files were being found, so the issue in my case 
occurred later...
Comment 6 Matthew Webster CLA 2005-09-23 08:32:59 EDT
Could you append the log (or at least the relevant parts)? Do you get weaving 
messages for the required classes (indicating they are being processed) but no 
weaveInfo messages (indicating there are no matches)? I assume the classes are 
not in com.crankj which is excluded or org.aspectj, java or javax which are 
also exluded automatically.

Have you looked at stderr? If an exception occurs during weaving it will be 
caught in the adaptor and logged but class loading will continue.
Comment 7 Alexandre Vasseur CLA 2005-10-24 05:52:18 EDT
Ron, can you update the status of this one?
Does it still stands or?
Comment 8 Ron Bodkin CLA 2005-10-25 03:24:44 EDT
This is still a bug. I just tried with a recent dev build (Oct. 21) and I see 
the same behavior: I have a simple trace aspect in my Web application that 
works with load-time weaving (it is compiled in but there's also an aop.xml 
file that is showing as weaving when I deploy just the app).

When I add a jar with load-time weaving to the parent classloader's classpath 
(i.e., Tomcat's shared lib directory), the Web application's LTW aspect no 
longer has an affect. I cranked up verbose weave information and you can see 
that the weaver is loading the aop.xml definitions, but it is not applying the 
advice from the child classloaders'

...
info using aspectpath: []
info zipfile classpath entry does not exist: C:\java\jrockit-jdk1.5.0_03
\jre\lib\i18n.jar
info zipfile classpath entry does not exist: C:\java\jrockit-jdk1.5.0_03
\jre\lib\sunrsasign.jar
info directory classpath entry does not exist: C:\java\jrockit-jdk1.5.0_03
\jre\classes
info register classloader org.apache.jasper.servlet.JasperLoader@5075224
info using file:/C:/jakarta-tomcat-5.5.9/shared/lib/crankjAgent.jar!/META-
INF/aop.xml
info using /C:/jakarta-tomcat-5.5.9/webapps/jpetstore/WEB-INF/classes/META-
INF/aop.xml
Comment 9 Alexandre Vasseur CLA 2005-10-28 08:06:04 EDT
cannot reproduce
see test AtAjLtwTests.testAppContainer()
look for AppContainerTest.java in tests/ module
see the sandbox to get an hint on how the rather complex test case works
(simulates on container with 2 deployed apps, sharing same classname inside like
compiled jsp can, with a global aspect, and one local aspect in only one of the
deployed app)
Comment 10 Adrian Colyer CLA 2005-10-28 08:19:02 EDT
just moved to P2 to make sure we close this out one way or another before RC1
Comment 11 Alexandre Vasseur CLA 2005-11-03 04:21:59 EST
Ron, can you provide a test case for that one ?
I could not reproduce it.
Comment 12 Ron Bodkin CLA 2005-11-04 02:30:34 EST
Fixed in recent builds.