Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error! The first argument to the non-static Java function 'replace' is not a valid object reference

Tags:

junit

eclipse

ant

I am trying to get ANT to create an HTML report of a JUNIT test in Eclipse but after I created the ANT build I get the following errors when I run it:

[junitreport] Processing C:\Documents and Settings\Administrator\workspace\Home\junit\TESTS-TestSuites.xml to C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\null785926900
[junitreport] Loading stylesheet jar:file:/C:/ANT/apache-ant-1.8.3/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 C:\Documents and Settings\Administrator\workspace\Home\junit\TESTS-TestSuites.xml

What do I need to do to fix this?

Here are the sections of my Build.xml I am trying to run:

<target name="Home">
    <mkdir dir="${junit.output.dir}"/>
    <junit fork="yes" printsummary="withOutAndErr">
        <formatter type="xml"/>
        <test name="Home" todir="${junit.output.dir}"/>
        <classpath refid="Home.classpath"/>
    </junit>
</target>
<target name="junitreport">
    <junitreport todir="${junit.output.dir}">
        <fileset dir="${junit.output.dir}">
            <include name="TEST-*.xml"/>
        </fileset>
        <report format="frames" todir="${junit.output.dir}"/>
    </junitreport>
</target>
like image 259
user1397000 Avatar asked May 15 '12 19:05

user1397000


5 Answers

The Bug was introduced in Java 7u5 according to this comment. Another comment explains how to workaround it, changing the bootclasspath. (DISCLAIMER: I didn't try and test this.)

This solution, however, worked fine for me:

  • Download ant-1.9.4
  • Eclipse>>Preferences>>Ant>>Runtime>>AntHomeEntries
  • Remove all 1.8.x classpath entries
  • Add all libs from 1.9.4 instead

According to Ant Changes, this has been fixed since 1.9.1

like image 97
Jörg Avatar answered Oct 14 '22 06:10

Jörg


When I got this error I had to right click on my build.xml file in Eclipse, choose the "Run as Ant build..." option (3rd one in the menu) then click the JRE tab and select the "Run in the same JRE as the workspace" option and then proceeded to run the script. For some reason this fixed the problem. I honestly don't know why.

like image 32
Kal Avatar answered Nov 12 '22 19:11

Kal


The Eclipse Bug is clearly documented Bug 384757. The analysis suggests that Oracle introduced the bug. I need Java version 7 but JunitReport needs Java version 5 and early versions of Java version 6. The obvious way is to add the "bootclasspath" argument to the Ant junitreport task while the Java problem is fixed by Oracle in a future release. Unfortunately Ant task junitreport does not support the bootclasspath option. Is this something the people supporting Ant could do?

like image 9
MikeBach Avatar answered Nov 12 '22 20:11

MikeBach


I met this situation while running my java program on Ubuntu 12.04 with *java 1.7.0_51* on Eclipse SDK Juno. I take Bhagyaraj's suggestion which is using apache-ant-1.9.2 instead. (p.s. The default ant version of Eclipse Juno is *org.apache.ant_1.8.3*, and I use apache-ant-1.9.3)

You may following my steps to setup.

  1. Download apache-ant-1.9.3-bin.zip and extract to a place where you want.
  2. Open your eclipse and choose Window --> Preferences
  3. You can see the Preferences window. On the left hand side please choose ant --> runtime
  4. Now focus on right hand-site of the window. Make sure you are now on Classpath tab and choose Ant Home Entries(Default).The buttons on the right which is Ant Home... is now click-able.
  5. No doubt, click on Ant Home... button and choose the folder where your ant-1.9.3 is. In this step, if you choose wrong folder, Eclipse may show the error message something like Specified Ant home does not contain a "lib" directory. If you choose the right directory, Ant Home Entries(Default) will become **Ant Home Entries()
  6. Don't forget to click apply.

After change those, while you right click on build.xml file and choose Run --> 1 Ant Build, the error message won't show because your ant is now 1.9.3.

I also download apache-ant-1.8.4 to run my build file, but the error can't be solved.

like image 4
Charles Wu Avatar answered Nov 12 '22 21:11

Charles Wu


I used the jdk1.6.45 and latest apache-ant-1.9.2-bin\

Problem solved.

As per note on MikeBach

This is bug#, please read: https://bugs.eclipse.org/bugs/show_bug.cgi?id=384757 Fixed in Ant.

Regards, Bhagyaraj

like image 3
Bhagyaraj Avatar answered Nov 12 '22 19:11

Bhagyaraj