This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Testing and the fly likes Application error when running an Junit test case Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Application error when running an Junit test case" Watch "Application error when running an Junit test case" New topic
Author

Application error when running an Junit test case

ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
I'm having an problem when running an junittestcase on a java class(which extends another class)
The error trace is:
junit] arguments are not type compatible (class: org/apache/log4j/LogManager method: <clinit>()V) at pc: 18
junit] java.lang.VerifyError: arguments are not type compatible (class: org/apache/log4j/LogManager method: <clinit
at pc: 18


consider I'm running a test case on a class c which extends class B.
These class B has a Logger in which error is showing.
When I'm instantiating Class C on my test case, it will normally call its superclass constructor(i.e B) in which the java.lang.verify error surfaces

class C extends B
{
}

class B
{
//Here in the following line the above error java.lang.verify error is showing up
private static Logger m_cat = Logger.getLogger(MLBatchProcessSetup.class);
}

}


Note when I'm building the application these classes are running properly, but only when I'm running an test case it throws the java.lang.verify error.
Can anybody throw some light on this?
Regards.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
when I go through that sun site, the reason for that error is mentioned as:
java.lang.verifyerror gets
Thrown when the "verifier" detects that a class file, though well formed, contains some sort of internal inconsistency or security problem.

This the url of that link:
java.lang.verifyError
With this can anyone throw their insights.
Regards.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
This link also provides some very valid inputs into the problem.
Fixing java.lang.verifyError
But I don't know how this can be resonated in my case.
Regards.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
The main problem is that Logger of that super class does not gets instantiated.
But when I'm building the application , it's working fine, only when I'm testing the implementation by writing an API Test case these verifyError surfaces.
Regards.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
I'm using jdk1.3 version.
Regards
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

It sounds like you are using differents version of the Log4J library when you compile your software and in the runtime environment. Make sure you use exactly the same Log4J JAR files.

What version of Log4J are you using? Are you sure you're using a version that is compatible with Java 1.3?

Also, make sure that you are compiling your source code with the JDK version that matches exactly with the runtime version that you're using. So, make sure that you're using JDK 1.3 to compile your source code, if you're running it on Java 1.3.

Are you compiling and running the software on the same environment (same operating system, etc.)?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
It sounds like you are using differents version of the Log4J library when you compile your software and in the runtime environment. Make sure you use exactly the same Log4J JAR files.

When I searched for jar files, I found only these jars for log files.
log4j.jar
log4j_patch.jar

1)These log4j_patch.jar is located in C:\CustomizationsWorking\deploy\approot\WEB-INF\lib and also in C:\CustomizationsWorking\customresources\lib
log4j.jar is located in C:\CustomizationsWorking\deploy\approot\WEB-INF\lib

2) Both of these jar files contains a class LogLog.class.( Is the error surfaces due to these issue both of the jars contains the same class)

3) This LogLog.class is the only class in log4j_patch.jar

What version of Log4J are you using? Are you sure you're using a version that is compatible with Java 1.3?

I'm using the above mentioned jar files & don't know if it is compatible with jdk1.3.
But one thing is sure.
When i build & test the application under RegressionTestBed(RTB) environment it is working fine, but when I try to run it through my test case, it is throwing the java.lang.verifyError.(the exact error trace in my first post)

Are you compiling and running the software on the same environment (same operating system, etc.)?


Yes

Also, make sure that you are compiling your source code with the JDK version that matches exactly with the runtime version that you're using. So, make sure that you're using JDK 1.3 to compile your source code, if you're running it on Java 1.3.

How to check this one?
Regards.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Any replies?
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Originally posted by ramya narayanan:

How to check this one?
Regards.


Read the release notes...
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
If you could brief me I appreciate it.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Both of these jar files contains a class LogLog.class.( Is the error surfaces due to these issue both of the jars contains the same class)
Regards.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38467
    
  23
I don't think this is a real beginner's subject. Moving thread.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
To give clarity, I hereby present the Testcase which I've written
package p2;
import com.trilogy.util.override.BundleStack;
import com.trilogy.util.override.BundleStackFactory;
import com.trilogy.ffc.html.FFCTracer;
import com.trilogy.sc.ISCCMProduct;
import p1.A;
import junit.framework.JUnit4TestAdapter;
import junit.framework.Assert;

import java.util.Vector;
import org.junit.Test;
import java.lang.reflect.*;
import com.trilogy.fs.dms.core.validator.test.ValidatorTestCase;

public class ATest extends ValidatorTestCase {
public static junit.framework.Test suite() {
System.out.println("In Test suite");
return new JUnit4TestAdapter(ATest.class);
}

@Test (timeout = 50000)
public void processCompEventsTest() throws Throwable{
System.out.println("Inside API Test case method to test the compevent processing ..... SAI...");
Class c=Class.forName("A");
//These processCompEvents is a protected method in A class
Method m = c.getDeclaredMethod("processCompEvents", null);
m.setAccessible(true);
m.invoke(c, null);
}

}


I've written an ant target to run this:



<target name="Custom.test" depends="-SetCustomClasspathForTest, Custom.test-init, Custom.TestBuild">
<junit printsummary="false" errorProperty="test.failed" failureProperty="test.failed" fork="yes">
<classpath refid="ATF.classpath"/>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<batchtest todir="${test.reports.dir}/jtf/data">
<fileset dir="${test.classes.dir}" includes="**/*Test.class" excludes="**/*Task.class,com/ml/inst/icp/loader/validator/*Validator.class"/>
</batchtest>
</junit>
<junitreport todir="${test.reports.dir}/jtf/data">
<fileset dir="${test.reports.dir}/jtf/data">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${test.reports.dir}/jtf"/>
</junitreport>
<fail message="Tests failed. Check log and/or reports." if="test.failed"/>
</target>


When I run this target by issuing this command:

ant -buildfile test\test.xml Custom.test -Denvironment=LOCAL


It's giving the following error trace:


[junit] arguments are not type compatible (class: org/apache/log4j/LogManager method: <clinit>()V) at pc: 18
[junit] java.lang.VerifyError: arguments are not type compatible (class: org/apache/log4j/LogManager method: <clinit
>()V) at pc: 18
[junit] at java.lang.J9VMInternals.verifyImpl(Native Method)
[junit] at java.lang.J9VMInternals.verify(J9VMInternals.java:55)
[junit] at java.lang.J9VMInternals.initialize(J9VMInternals.java:124)
[junit] at org.apache.log4j.Logger.getLogger(Logger.java:94)
[junit] at com.metlife.inst.icp.engine.Bsuper.<clinit>(Bsuper.java:32)
[junit] at java.lang.J9VMInternals.initializeImpl(Native Method)
[junit] at java.lang.J9VMInternals.initialize(J9VMInternals.java:161)
[junit] at java.lang.J9VMInternals.initialize(J9VMInternals.java:140)
[junit] at java.lang.Class.forNameImpl(Native Method)
[junit] at java.lang.Class.forName(Class.java:131)


The following line is in Bsuper which is a superclass for my A .java
on which I'm running the test case.
In line no 32 of Bsuper
private static Logger m_cat = Logger.getLogger(Bsuper.class);


The following are the structure in which the test case classes & log4j jars are present

1)ValidatorTestCase.class in present in C:\.....\Test\lib as a jar file in which junit4.3.jar is also present

2) The error showing LogManager.class is present in log4j.jar present in C:\CustomizationsWorking\deploy\approot\WEB-INF\lib

3) The other log jar log4jpatch.jar is located in two places:
C:\CustomizationsWorking\deploy\approot\WEB-INF\lib
C:\CustomizationsWorking\customresources\lib


Regards.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Any replies?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30356
    
150

Ramya,
It sounds like your compile time and runtime classpaths are using different jars. Or that you have two copies of the same jar in your classpath.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Now I've fixed this java.lang.verifyError.
Actually the problem is not with log4j installation jars or classpath or not.
The main problem is with logger instantiation.
When I remove the loggers in my .java & in its dependent classes(superclasses or composition classes) it's working fine.
But seriously I don't know why my testcase written in junit-4.3 & ant1.6 & the log jars I'm using are log4j.jar & log4j_patch.jar.
Anyhow thanks for all the good hearts who supported me in this endeavour.
Regards.
Prashant Choudhary
Greenhorn

Joined: May 07, 2012
Posts: 1
Hi Ramya,

I am facing a similar error when running hot code plugin on Eclipse.

Here is the complete stack trace :


Redefining the class...
* Redefining amdocs.oms.apcore.ApItem
Exception in thread "main" java.lang.VerifyError: verifier detected internal inc
onsistency or security problem
at com.sun.tools.jdi.VirtualMachineImpl.redefineClasses(VirtualMachineIm
pl.java:296)
at SwapperEnc.main(SwapperEnc.java:119)


Can you suggest a possible trouble shoot for this ? We are stuck with this all day.

I am working on J2sdk 1.4 update 7.

Thanks
Prashant


 
 
subject: Application error when running an Junit test case