Bug 10931

Summary: JUnit classloading Broken
Product: Ant Reporter: Jamie Lawson <jrlawson>
Component: Core tasksAssignee: Ant Notifications List <notifications>
Status: RESOLVED DUPLICATE    
Severity: critical CC: jrlawson
Priority: P3    
Version: 1.5   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Jamie Lawson 2002-07-18 01:23:06 UTC
When I upgrade to Ant 1.5 my JUnit targets (that worked perfectly under 
1.4.1) barf. It seems like I don't have an appropriate parser. What should I 
do????? I get the following trace:

maketestreports:
    [junit] Running 
test.com.mantra.huxley.ga.predicate.UnitTest_AndStopPredicate

BUILD FAILED
java.lang.LinkageError: loader constraints violated when linking 
org/w3c/dom/Document class
        at 
org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(DocumentBui
lderFactoryImpl.java:88)
        at 
org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter.getDocument
Builder(XMLJUnitResultFormatter.java:
93)
        at 
org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter.startTestSu
ite(XMLJUnitResultFormatter.java:138)

        at 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.fireStartTestSuite(
JUnitTestRunner.java:433)
        at 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner
.java:279)
        at 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.jav
a:804)
        at 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:55
1)
        at 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:52
7)
        at org.apache.tools.ant.Task.perform(Task.java:317)
        at org.apache.tools.ant.Target.execute(Target.java:309)
        at org.apache.tools.ant.Target.performTasks(Target.java:334)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1250)
        at org.apache.tools.ant.Main.runBuild(Main.java:610)
        at org.apache.tools.ant.Main.start(Main.java:196)
        at org.apache.tools.ant.Main.main(Main.java:235)


The target looks like this:

<target name="maketestreports" depends="init,compile">
    <junit printsummary="yes" haltonfailure="yes">
        <formatter type="xml" usefile="yes" />
        <classpath>
            <pathelement path="${temp.classes}" />
            <pathelement path="${model.classpath}" />
            <pathelement path="${product.classpath}" />
            <pathelement path="${java.class.path}" />
        </classpath>
        <batchtest todir="${metrics.dir}/unittests">
    	    <fileset dir="${classes.dir}">
      	        <include name="test/**/*UnitTest_*.class" />
    	    </fileset>
  	</batchtest>			
    </junit>
</target>
Comment 1 Joachim Simon 2002-07-23 09:24:20 UTC
In AntClassLoader(ClassLoader parent, Project project, Path classpath, boolean
parentFirst) the package prefixes of jre packages are set.
Changing the code to

        addJavaLibraries();
//        addSystemPackageRoot("java");
//        addSystemPackageRoot("javax");

solved the problem. But perhaps there still was a reason for commenting out the
call to addJavaLibraries?
There is also a bug (one dot too many) in JavaEnvUtils.buildJrePackages(),
called from addJavaLibraries, in the default branch of the switch statement,
which lead to a ClassNotFoundException for sun.**.
Comment 2 Steve Loughran 2002-07-23 18:15:14 UTC
Joachim: We havent turned the addLibraries() on for ant1.5 as it went in too
late for rigorous testing, so it was left off, but left in there for people in
emergencies. I might just turn it on now in the 1.6alpha to see what happens.
Corrected the "sun." to "sun", though, since we just use indexOf, it may be
better to go the other way and have sun., java. javax., etc in the list. 
Comment 3 Steve Loughran 2002-07-23 18:17:47 UTC
Jamie.

One change from 1.4.1 to 1.5 is the move to xerces over crimson. we did find
some funnies with locating xml parsers in the betas, but thought we had fixed
them with a modification of the manifest of ant.jar

What happens if you fork junit?
Comment 4 Stephane Bailliez 2002-08-16 15:26:17 UTC
Setting as duplicate to the meta bug concerning classloaders and 
changed 'formatter' to 'classloading' in the summary title as it was 
misleading.

*** This bug has been marked as a duplicate of 6606 ***