Bug 317874 - race condition when LTW - classes loaded before initialization completes are not woven
Summary: race condition when LTW - classes loaded before initialization completes are ...
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: LTWeaving (show other bugs)
Version: 1.6.9RC1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-24 14:57 EDT by Andrew Clement CLA
Modified: 2010-06-25 10:30 EDT (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 Andrew Clement CLA 2010-06-24 14:57:06 EDT
Raised on the list by Peter Melnikov:

---
What I have found is that aspect is not applied to my servlet classes. While debugging the AspectJ I discovered that there are racing conditions in Aj.java when I run application under Tomcat. WeavingAdaptor initialization has not been complete yet (see line 254) when Tomcat loads servlet classes using TomcatInstrumentableClassLoader. Thought there are synchronized section but it only ensures that only one instance per classloader will be created. While WeavingAdaptor is not initialized yet and  ClassLoaderWeavingAdaptor's field enabled is false that prevents class from being weaved:
WeavingAdaptor.java (line 294):
if (!enabled) {
 	 if (trace.isTraceEnabled()) {
 	 trace.exit("weaveClass", false);
 	 }
 	 return bytes;
 	 }

23.06.2010 18:45:16 org.aspectj.weaver.loadtime.Aj preProcess
FINER: EVENT
23.06.2010 18:45:16 org.aspectj.weaver.tools.WeavingAdaptor weaveClass
FINER: ENTRY org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor@1d0740e
23.06.2010 18:45:16 org.aspectj.weaver.tools.WeavingAdaptor weaveClass
FINER: ENTRY net/mansion/redirect/impl/engine/web/RedirectProcessorServlet/class byte[12079]
23.06.2010 18:45:16 org.aspectj.weaver.tools.WeavingAdaptor weaveClass
FINER: RETURN false
In AspectJ output to stdout there is no messages like "weaving [class name]" or "not weaving [class name]" that could said that class is processed with weaver (no servlet classes mentioned at all).
When initialize method of ClassLoaderWeavingAdaptor is complete, I see that messages but for other classes of my application.
Has any one run into this issue before?
Comment 1 Peter Melnikov CLA 2010-06-25 10:30:01 EDT
Problem appears only when TomcatInstrumentableClassLoader is used.

context.xml.default:

<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"
 useSystemClassLoaderAsParent="false" />

Spring's application-context.xml:

...
<context:load-time-weaver/>
...

If spring's context initialization is turned off (org.springframework.web.context.ContextLoaderListener commented out in web.xml) weaving does not occur at all, even if there are servlets in web.xml that are targets of aspect to be applied to. 

When -javaagent option is used in catalina.bat instead to run aspectjweaver problem goes away and servlets are weaved.