How to remove a non existing inherit final error?
I'm using junit 4.8.1 and I run all jUnit test of the 6 Projects from the eclipse project called AllTests, which looks like this
package ch.mct.jdyna.tests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
ch.mct.jdyna.core.duplicatechecking.AllTests.class,
ch.mct.jdyna.core.matching.AllTests.class,
ch.mct.jdyna.core.matchingoptimization.AllTests.class,
ch.mct.jdyna.core.textanalysis.testing.AllTests.class,
ch.mct.jdyna.dataaccesslayer.testing.AllTests.class,
ch.mct.jdyna.dataacquisition.testing.AllTests.class,
})
public class AllTests {
}
In the projects I also have a file in the same style calling all jUnit tests of the project itself. The Problem is, when I call the test method testCreateProfiles() from the global context, there is an error, from the class AllTests in the Project itself everything is green.
The Method to test:
/**
* Test method for
* {@link ch.mct.jdyna.dataacquisition.CvPreprocessing#createProfiles(java.util.List)}
* .
*/
@Test
public final void testCreateProfiles() {
List<Cv> cvs = new LinkedList<Cv>();
for (int i = 0; i < 10; ++i)
cvs.add(testingCv);
List<CurriculumVitae> actualList = CvPreprocessing.createProfiles(cvs);
assertEquals(cvs.size(), actualList.size());
}
The Method under test:
/**
* Creates CurriculumVitae from the given data in CV.
*
* @param cvList
* the CVs data
* @return the list of CurriculumVitae
*/
public static List<CurriculumVitae> createProfiles(List<Cv> cvList) {
if (cvList == null)
return null;
List<CurriculumVitae> cvProfileList = new ArrayList<CurriculumVitae>();
for (Cv cv : cvList) {
String title = cv.getTitle();
if (title != null)
title = title.substring(0,
Math.min(title.length(), MAXIMAL_TITLE_LENGTH - 1));
String body = mergeBody(cv);
Date date = cv.getLastUpdate();
Calendar cal = Calendar.getInstance();
if (date != null)
cal.setTime(date);
BigDecimal externalId = cv.getId();
CurriculumVitae cvProfile = new CurriculumVitae(title, body, cal,
externalId);
cvProfileList.add(cvProfile);
}
return cvProfileList;
}
The error is:
java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at ch.mct.jdyna.dataacquisition.CvPreprocessing.createProfiles(CvPreprocessing.java:71)
at ch.mct.jdyna.dataacquisition.testing.CvPreprocessingTest.testCreateProfiles(CvPreprocessingTest.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
开发者_开发知识库at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Does anyone have experience with this kind of problem?
Thanks in advance. Manu
Most often those verify error signal some problem with different libraries: like you use one version of library to compile the classes and another one to run or test the application.
A compiler won't allow subclassing a final class. So if you see this problem at runtime, you probably subclassed an external non-final class (which is ok) but added a different version of this class (now a final class) to the classpath. This will create this type of VerifyError at runtime.
So double check your classpaths. Make sure, the classpaths you use for building and testing include the same libraries. Investigate in the offending class (the one that now subclasses a final class) and try to locate the superclass(es).
My guess is that in the method ch.mct.jdyna.dataacquisition.CvPreprocessing.createProfiles()
at line 71
, code is trying to create an anonymous class the extends form some class that in declared as final
.
Thanks Andreas_D for the detailed reason. Got stuck with the same exception. Fixed it by following pom files. Here is the note to figure out that. Check the stack trace and find the last class that caused the error. In this example it was 'CvPreprocessing.createProfiles'. This method uses some class which causes the issue. So, had to search the pom file which builds the jar containing 'CvPreprocessing'. All those dependencies defined there had to be checked on whether a same jar with different version was already in my project. In my case the class that threw the error was 'org.apache.http.impl.client.DefaultHttpClient'. This is httpclient jar which uses httpcore jar. And in my app a different version of http core was already present.
精彩评论