2011-08-31 3 views
0

나는 또한 같은 스타일의 파일이 나는 JUnit을 4.8.1을 사용하고 있는데 나는 프로젝트에서이기존의 상속하지 않는 최종 오류를 제거하는 방법은 무엇입니까?

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 { 

} 

처럼 보이는 ALLTESTS라는 이클립스 프로젝트에서 6 개 프로젝트의 모든 JUnit 테스트를 실행 프로젝트 자체에 대한 모든 jUnit 테스트를 호출합니다. 문제는 전역 컨텍스트에서 테스트 메서드 인 testCreateProfiles()를 호출 할 때 AllTests 클래스 자체에서 녹색으로 표시되는 오류입니다.

시험에있어서 시험

/** 
* 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()); 
} 

에있어서

/** 
* 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; 

} 

오류는 다음과 같습니다

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) 

사람이 이런 종류의 문제에 대한 경험이 있습니까

?

미리 감사드립니다. 마누

+0

ch.mct.jdyna.dataacquisition.CvPreprocessing.createProfiles 코드를 게시 할 수 있습니까? –

답변

6

대부분의 경우 이러한 오류는 다른 라이브러리에서 발생하는 몇 가지 문제를 나타냅니다. 한 버전의 라이브러리를 사용하여 클래스를 컴파일하고 다른 버전을 사용하여 응용 프로그램을 실행하거나 테스트 할 수 있습니다.

컴파일러는 최종 클래스의 서브 클래 싱을 허용하지 않습니다. 따라서 런타임에이 문제가 발생하면 외부의 final이 아닌 클래스를 서브 클래스로 만들었지 만이 클래스의 다른 버전 (현재는 최종 클래스)을 클래스 경로에 추가했습니다. 그러면 런타임에이 유형의 VerifyError가 작성됩니다.

그래서 클래스 경로를 다시 확인하십시오. 빌드 및 테스트에 사용하는 클래스 경로에 동일한 라이브러리가 포함되어 있는지 확인하십시오. 문제가되는 클래스 (이제 최종 클래스를 하위 클래스로 분류하는 클래스)를 조사하고 수퍼 클래스를 찾으십시오.

+0

고마워,이 진짜로 나를 도왔다. 나는 많은 라이브러리 (항상 같은 버전)를 공유하는 두 개의 프로젝트를 가지고 있었지만 아직이 프로젝트들을 결합하지는 못했습니다. 내가하고 4 개의 새로운 라이브러리를 추가 한 후에 모든 것이 잘 작동합니다. – Manu

0

내 생각 엔 라인 71의 방법 ch.mct.jdyna.dataacquisition.CvPreprocessing.createProfiles()에, 코드가 final로 선언 몇 가지 클래스를 형성 확장 익명 클래스를 생성하려고하는 것입니다.

+0

맞는지는 모르겠지만 ... 이미 컴파일러 오류가 발생하지 않아야합니까? –

0

자세한 이유는 Andreas_D에 감사드립니다. 동일한 예외가 붙어 있습니다. pom 파일을 따라 가려는 문제를 해결했습니다. 그걸 알아내는 메모가 있습니다. 스택 추적을 확인하고 오류를 일으킨 마지막 클래스를 찾으십시오. 이 예제에서는 'CvPreprocessing.createProfiles'입니다. 이 메서드는 문제를 일으키는 클래스를 사용합니다. 그래서, 'CvPreprocessing'을 포함하는 jar를 빌드하는 pom 파일을 검색해야했습니다. 거기에 정의 된 모든 종속성은 다른 버전의 동일한 jar가 이미 내 프로젝트에 있는지 여부를 확인해야했습니다. 내 경우에는 오류를 던진 클래스는 'org.apache.http.impl.client.DefaultHttpClient'입니다. httpcore jar를 사용하는 httpclient jar입니다. 그리고 내 애플 리케이션에서 http core의 다른 버전이 이미 존재했다.

관련 문제