Bug 117885 - Classes are reloaded in AjcTestCase.run() which is confusing, inconsistent and unrepresentative
Summary: Classes are reloaded in AjcTestCase.run() which is confusing, inconsistent an...
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P5 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-24 06:11 EST by Matthew Webster CLA
Modified: 2007-10-23 11:36 EDT (History)
0 users

See Also:


Attachments
Patch (2.67 KB, application/octet-stream)
2005-11-24 16:33 EST, Matthew Webster CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Webster CLA 2005-11-24 06:11:21 EST
When running an XMLBasedAjcTestCase a new class loader is created with the sandbox on the classpath. This allows testcases to be isolated from each other. It also facilitates load-time weaving (Bug 107741). Unfortunately the URLClassLoader is created with the boot class loader (null) as its parent and all the org.aspectj modules are added to the classpath. This can cause ClassCastExceptions in the harness because there are 2 copies of each AspectJ class in the system, is not consistent with ordinary JUnit testcases which all use the same copy of the classes and is not representative of a runtime environment where it is unlikely the same class loader will be used to load both AspectJ and the user’s application. In fact bug 116229 and bug 116254 were raised because the new PointcutParser and AjTypeSystem interfaces made this assumption.
Comment 1 Matthew Webster CLA 2005-11-24 16:33:52 EST
Created attachment 30584 [details]
Patch

This approach was introduced in the LTW harness enhancement. It should also speed up running the tests. Also included fix to Java15ReflectionBasedReferenceTypeDelegate and testcase.
Comment 2 Adrian Colyer CLA 2005-11-27 13:40:23 EST
fix to reference type delegate and tests included under fix for 116229, patch for harness not yet applied.
Comment 3 Matthew Webster CLA 2006-06-15 06:54:28 EDT
The implementation of AjcTestCase.run() has changed considerably while fixing the Class.forName() problem in Bug 140695. Now a completely new classloader is created for AspectJ each time a test is run. Ideally we should just delegate to the System classloader but it can have the wrong classpath (see http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg02066.html).

Changes to project dependencies should eventually solve the classpath problem however we also need to deal with misuse of Class.forName(). The sandbox classloader should not delegate requests for weaver classes unless explicitly configured in the test. This could be implemented using an OSGi-style FilteringDelegateClassLoader.