java.lang.IllegalAccessError - tried to access method junit.framework.TestCase.()V

1 minute read

Seems this error happens when running ANT 1.7 and JUnit 3.8.1. The quick solution is upgrade junit to 3.8.X.

The cause as i can make out at this time is this. The junit task in the ant script forks a new jvm which creates a new classloader, this correctly picks up the junit 3.7.1 jar. Between 3.7 and 3.8.1 junit changed the default method name for getting the test name, from name() to getName(). ANT 1.7 in this case, first checks the junit version and then attempts to use reflection to call the correct test name method, but since the Task class has a protected constuctor method and there is a new classloader this IllegalAccessError is thrown.

The method name change is correct, the reflection stuff is correct but the classloader stuff is probally smack.

<pre name="code" class="java">
C:\Develop\UIClaims50_PeriodicBuilder\UI\UITools\components\cruisecontrol\projects\build-ant.xml:94: The following error occurred while executing this line:
C:\Develop\UIClaims50_PeriodicBuilder\UI\EJBServer\ant\uiclaims.junit.xml:43: java.lang.IllegalAccessError: tried to access method junit.framework.TestCase.()V from class org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl$VmExitErrorTest
at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:541)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:418)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor170.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)

at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: C:\Develop\UIClaims50_PeriodicBuilder\UI\EJBServer\ant\uiclaims.junit.xml:43: java.lang.IllegalAccessError: tried to access method junit.framework.TestCase.()V from class org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl$VmExitErrorTest
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:115)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
… 16 more
Caused by: java.lang.IllegalAccessError: tried to access method junit.framework.TestCase.()V from class org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl$VmExitErrorTest
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl$VmExitErrorTest.(JUnitTaskMirrorImpl.java:80)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl.addVmExit(JUnitTaskMirrorImpl.java:55)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.logVmExit(JUnitTask.java:1446)
</pre>

Categories:

Updated:

Leave a Comment