Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 384757 - Ant build fails in junitreport using Java 6u32 or later
Summary: Ant build fails in junitreport using Java 6u32 or later
Status: RESOLVED NOT_ECLIPSE
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Ant (show other bugs)
Version: 4.2   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-10 13:24 EDT by Steven Darnell CLA
Modified: 2014-05-07 23:07 EDT (History)
11 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steven Darnell CLA 2012-07-10 13:24:02 EDT
Build Identifier: Version: Indigo Service Release 1 Build id: 20110916-0149

When building a project with Junit tests with ant from the Eclipse IDE using Java 6 build 32 or later, the following error occurs:

 [junitreport] Processing /MYPATH/junit/html/TESTS-TestSuites.xml to /var/folders/Hh/HhhDpmqxFISJ84nX-yGYY++++TI/-Tmp-/null191644350
 [junitreport] Loading stylesheet jar:file:/MYPATH/eclipse/plugins/org.apache.ant_1.8.2.v20110505-1300/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
 [junitreport] : Error! The first argument to the non-static Java function 'replace' is not a valid object reference.
 [junitreport] : Error! Cannot convert data-type 'void' to 'reference'.
 [junitreport] : Fatal Error! Could not compile stylesheet
 [junitreport] Failed to process /MYPATH/junit/html/TESTS-TestSuites.xml

Here are configurations that have failed:

Windows 7, Eclipse 3.6.2 32-bit, JDK 1.6.0_32, Ant 1.7.2, Junit 4.8.1
Windows 7, Eclipse 3.7.2 32-bit, JDK 1.6.0_32, Ant 1.7.2, Junit 4.8.1
Windows 7, Eclipse 3.7.2 32-bit, JDK 1.6.0_32, Ant 1.7.4 (from Apache, current), 4.8.1
Mac 10.6, Eclipse 3.7.1 32-bit, JDK 1.6.0_33, Ant 1.7.2, Junit 4.8.1

As reported from this StackOverflow question (http://stackoverflow.com/questions/10536095/ant-junit-build-error-inside-eclipse), builds succeed using the same ant script when run from outside of Eclipse.

On Windows, my current workaround is to use Java 6 build 31; however, this is not a satisfying solution. On Mac, Apple has updated Java to build 33 and rolling back Java is not straight forward.

Reproducible: Always

Steps to Reproduce:
1. Build a project with Junit tests with ant from the Eclipse IDE
2.
3.
Comment 1 Steven Darnell CLA 2012-07-10 17:24:06 EDT
Another configuration that failed:

Windows 7, Eclipse 4.2 32-bit, JDK 1.6.0_33, Ant 1.7.3, Junit 4.8.1
Comment 2 Steven Darnell CLA 2012-07-11 16:26:32 EDT
Correction for Comment #0:

A headless build fails in the same manner using antRunner in Eclipse.

Mac 10.6, Eclipse 3.7.1 32-bit, JDK 1.6.0_33, Ant 1.7.2, Junit 4.8.1

"${ECLIPSE}" --launcher.suppressErrors -noSplash -clean -data "${ECLIPSE_WORKSPACE}" \
	-vm "${JAVA}" -Dbuild=release -Dbuild.auto=true \
	-application org.eclipse.ant.core.antRunner -buildfile "${BUILDFILE}"
Comment 3 Ioannis Oikonomou CLA 2012-07-23 04:25:12 EDT
I confirm the same problem with:
Windows 7, Eclipse 3.7 (Indigo) 32-bit, JDK 1.6.0_32, Ant 1.8.4, Junit 4.10
I had to revert back to JDK 1.6.0_31.

Thanks,
Ioannis
Comment 4 Markus Keller CLA 2012-08-09 14:59:46 EDT
This works fine with jdk6_31, jdk7_02, and IBM Java SDK 7.0 SR1, but it fails with current Oracle Java releases (jdk6_33 and jdk7_05).

XSLT instructions like this one have a problem when the Ant script is started from Eclipse:

<xsl:param name="tmp1" select="stringutils:replace(string($string),'\','\\')"/>


However, I just verified that this works fine with jdk7_05 when I launch Ant from the command line:

-showversion
-classpath .;C:\e\i\4.3-I-builds\plugins\org.apache.ant_1.8.3.v20120530-0730\lib\* 
-Dant.home=C:\e\i\4.3-I-builds\plugins\org.apache.ant_1.8.3.v20120530-0730\lib\
org.apache.tools.ant.Main
-f runAllTests.xml applyStylesheet


The bug is somewhere in our InternalAntRunner, or in some code that is run by the InternalAntRunner. I suspected it could be the AntSecurityManager, but commenting that one out doesn't help.

I'm investigating.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7167657 could be related.
Comment 5 Markus Keller CLA 2012-08-09 15:04:53 EDT
This TypeCheckError causes the problem. The friendly FunctionCall.typeCheck(SymbolTable) line: 385	
swallows this stacktrace:

Error checking type of an expression at an unknown location.
The first argument to the non-static Java function 'replace' is not a valid object reference.
	at com.sun.org.apache.xalan.internal.xsltc.compiler.FunctionCall.typeCheckExternal(FunctionCall.java:542)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.FunctionCall.typeCheck(FunctionCall.java:382)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.Param.typeCheck(Param.java:158)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:493)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.Template.typeCheck(Template.java:295)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:493)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.typeCheck(Stylesheet.java:657)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.createAST(Parser.java:408)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:369)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:454)
	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:852)
	at org.apache.tools.ant.taskdefs.optional.TraXLiaison.readTemplates(TraXLiaison.java:300)
	at org.apache.tools.ant.taskdefs.optional.TraXLiaison.createTransformer(TraXLiaison.java:317)
	at org.apache.tools.ant.taskdefs.optional.TraXLiaison.transform(TraXLiaison.java:178)
	at org.apache.tools.ant.taskdefs.XSLTProcess.process(XSLTProcess.java:819)
	at org.apache.tools.ant.taskdefs.XSLTProcess.execute(XSLTProcess.java:407)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
	at org.apache.tools.ant.Task.perform(Task.java:348)
	at org.apache.tools.ant.Target.execute(Target.java:392)
	at org.apache.tools.ant.Target.performTasks(Target.java:413)
	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
	at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
	at org.eclipse.ant.internal.core.ant.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
	at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
	at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:672)
	at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:498)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.ant.core.AntRunner.run(AntRunner.java:378)
	at org.eclipse.ant.internal.launching.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:298)
	at java.lang.Thread.run(Thread.java:722)
Comment 6 Markus Keller CLA 2012-08-09 15:43:24 EDT
In jdk7_02, the _namespace_format in com.sun.org.apache.xalan.internal.xsltc.compiler.FunctionCall.typeCheckExternal(SymbolTable) is NAMESPACE_FORMAT_CLASS.

This was set in FunctionCall.typeCheck(SymbolTable) line: 358, where ObjectFactory.findClassLoader() returned an AntClassLoader.

In jdk7_05, Oracle changed that line to use Class.forName(className) instead of ObjectFactory.findClassLoader() iff a security manager is active. This throws a ClassNotFoundException, and sets _namespace_format to NAMESPACE_FORMAT_PACKAGE, which later causes the wrong TypeCheckError from comment 5.

=> This is a bug that Oracle introduced, and I don't see a way to work around it in Eclipse.
Comment 7 Jan Hoppe CLA 2012-08-10 03:25:50 EDT
This one is fixed by apache ant: https://issues.apache.org/bugzilla/show_bug.cgi?id=51668
Comment 8 Markus Keller CLA 2012-08-10 05:58:50 EDT
Thanks for the link. Unfortunately, this patch didn't make it into Ant 1.8.3 nor 1.8.4.

And I still think this is a bug in the JDK that should be fixed there.
Comment 9 Markus Keller CLA 2012-08-10 10:41:26 EDT
The bug was introduced with Oracle jdk6_32 and jdk7_04 here:
http://java.net/projects/jaxp-sources/sources/svn/revision/3040

The Ant fix from comment 7 apparently doesn't fully address this problem when a SecurityManager is present.
Comment 10 Markus Keller CLA 2012-08-13 05:30:00 EDT
Assigning to me to make sure I don't lose track of this bug.

If anybody has connections to Oracle, please push them to look at
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7167657 or at this bug.
Comment 11 Markus Keller CLA 2012-09-21 10:19:30 EDT
Konstantin, do you have an idea how best to push the Oracle JDK team to fix the bug they introduced (comment 6)?
Comment 12 Markus Keller CLA 2012-09-27 05:52:20 EDT
Also causes bug 390494.
Comment 13 Markus Keller CLA 2012-09-28 06:25:12 EDT
I finally found a hack to work around the bug in Oracle's XSLT implementation. To replace the broken transformer with the original org.apache.xalan, you have to add this to the vmargs when running the Ant build:

-Djavax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl
-Xbootclasspath/a:${project_loc:/org.apache.xalan}
-Xbootclasspath/a:${project_loc:/org.apache.xml.serializer}

You can check out the two org.apache.* bundles from Orbit CVS or get them from http://download.eclipse.org/tools/orbit/downloads/ (or maybe they are already in your plugins folder). If you use the JARs, then replace the ${project_loc:*} so that you have the full OS path to the org.apache.* bundle there.
Comment 14 David Williams CLA 2012-10-04 14:01:36 EDT
There are two work arounds mentioned in bug 390494. 

Using the bootclasspath method as Paul mentioned, plus another
using -Djava.ext.dirs to specify location of xalan jars. 

So, a). Don't think this should be "blocker" any longer (since a workaround exist). and 
b) think this should be closed as "not eclipse". 

I've changed severity, but will leave to "ant team" to resolve as "not eclipse" if they agree.
Comment 15 lissan ettajani CLA 2013-02-24 15:04:05 EST
hallo all,

i am new to ant, and i have the same problem.

i saw your comment to the work round  bug in Oracle's XSLT implementation  To replace the broken transformer with the original org.apache.xalan.

in order to add the vmargs, i am not experienced in ant, can you please give me an example how should the ${project_loc:/org.apache.xml.serializer} looks like. specialy the "project_loc"
should i add the tasks to the Junit target?
thanks
lissan
Comment 17 Michael Rennie CLA 2013-03-06 08:58:45 EST
https://issues.apache.org/bugzilla/show_bug.cgi?id=54641#c2 mentions a 'fix' proposed on stack overflow. The Ant folks are testing it now - for the release in Ant 1.9.0
Comment 18 Markus Keller CLA 2013-03-06 15:29:24 EST
> https://issues.apache.org/bugzilla/show_bug.cgi?id=54641#c2 mentions a 'fix'

That fix works and is a good workaround for the Oracle bug in latest JREs.

If you can't wait for Ant 1.9.0, you can use the stylesheets from http://svn.apache.org/viewvc?view=revision&revision=1453414 . See the example at the end of http://ant.apache.org/manual/Tasks/junitreport.html for how to specify custom stylesheets.
Comment 19 Markus Keller CLA 2013-03-06 19:53:49 EST
(In reply to comment #18)
> If you can't wait for Ant 1.9.0, ...

Actually, it looks like the fix will not make it into Ant 1.9.0.
Comment 20 Jesse Glick CLA 2013-03-07 09:12:45 EST
(In reply to comment #19)
> it looks like the fix will not make it into Ant 1.9.0.

No. But the release manager for 1.9.0 has said he hopes to release 1.9.1 pretty soon.
Comment 21 Steven Darnell CLA 2013-06-28 14:00:27 EDT
Bug 395421 - Update to Ant 1.9.1 is assigned and currently scheduled for Eclipse 4.4. This bug should be fixed with the next Ant upgrade.