Bug 158205 - NullPointerException when weaving with bootstrap agent
Summary: NullPointerException when weaving with bootstrap agent
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: LTWeaving (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.5.3   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-21 15:25 EDT by Ron Bodkin CLA
Modified: 2012-04-03 16:16 EDT (History)
0 users

See Also:


Attachments
Proposed fix: patch to loadtime module (1018 bytes, patch)
2006-09-21 15:26 EDT, Ron Bodkin CLA
aclement: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ron Bodkin CLA 2006-09-21 15:25:13 EDT
We are using an updated version of Alex Vasseur's LTW agent for AspectJ (based on AspectWerkz) to do load-time weaving on a 1.4 VM. The agent is loaded from the bootstrap loader. However, a user has reported this NPE (see http://www.glassbox.com/forum/forum/viewthread?thread=67).

AspectWerkz - INFO - Pre-processor org.aspectj.ext.ltw13.ClassPreProcessorAdapter loaded and initialized
[AppClassLoader@7b7072] warning parse definitions failed -- (NullPointerException) null
null
java.lang.NullPointerException
at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.parseDefinitions(ClassLoaderWeavingAdaptor.java:180)
at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.initialize(ClassLoaderWeavingAdaptor.java:127)
...

In this case, the code is assuming that ClassLoader.getSystemClassLoader() is already set, but when the weaver is loaded through the bootstrap loader that appears to not be a good assumption. I propose to avoid this problem by testing for the system loader like this, so as to enable 3rd party agents that might run  before the system loader is set:

            if (loader!=null && loader.equals(ClassLoader.getSystemClassLoader())) {

I will be providing our user a patched version of AspectJ to test with this change to see if it does fix the problem.
Comment 1 Ron Bodkin CLA 2006-09-21 15:26:22 EDT
Created attachment 50659 [details]
Proposed fix: patch to loadtime module
Comment 2 Matthew Webster CLA 2006-09-22 09:15:40 EDT
Ron,

Thanks for the patch. I'd actually like to get rid of the undocumented "feature" ("-Daj5.def=...") altogether that is only there for testing. It means we don't test LTW in a representative way which has meant on at least one occasion (Bug 120473 "Don't Create Separate Weaving Adaptors for Reflection Loaders") we have been unable to reproduce problems. Unfortunately both you (http://rbodkin.blogs.com/ron_bodkins_blog/2005/10/websphere_loadt.html) and Alex (http://blogs.codehaus.org/people/avasseur/archives/001140_aspectj_5_load_time_weaving_with_java_13_using_aspectwerkz.html) have referenced it in your blogs even though there is no mention of it in the AspectJ LTW documentation. I trust you do not rely upon it.

I'd also like to add a test to the suite for these JDK 1.4 agents.
Comment 3 Matthew Webster CLA 2006-09-29 10:56:25 EDT
I now have a testcase that not only verifies this fix but will also give us an environment to test custom 1.3/1.4 LTW agents in the future. It involves prepending a replacement java.net.URLClassLoader to the bootclasspath which intercepts class defining and calls Aj, appending AspectJ to the bootclasspath, and finally specifying a custom SecurityManger using -Djava.security.manager. This will be loaded and woven _before_ the class loader hierarchy initialization is complete and when ClassLoader.getSystemClassLoader() will return null.
Comment 4 Matthew Webster CLA 2006-10-03 07:43:28 EDT
Fix available in aspectj-DEVELOPMENT-20061003103716.jar
Comment 5 Helen Beeken CLA 2006-11-09 08:38:35 EST
iplog