52

When upgrading from Surefire 2.6 to Surefire 2.13, I get a TypeNotPresentExceptionProxy when running my unit tests.

java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:653)
    at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:460)
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:286)
    at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:222)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
    at java.lang.Class.initAnnotationsIfNecessary(Class.java:3070)
    at java.lang.Class.getAnnotation(Class.java:3029)
    at org.apache.maven.surefire.common.junit4.JUnit4TestChecker.isValidJUnit4Test(JUnit4TestChecker.java:64)

In JUnit4TestChecker, line 64 looks like this:

Annotation runWithAnnotation = testClass.getAnnotation( runWith );

So Surefire inspects the @RunWith annotation to make sure its type is valid. Our tests use Spring, so @RunWith looks like this in our test classes:

@RunWith(SpringJUnit4ClassRunner.class)

It seems like Surefire isn't finding the SpringJUnit4ClassRunner class. I'm not sure why since under Surefire 2.6, the tests run fine.

Any ideas?

Nicolas Henneaux
  • 11,507
  • 11
  • 57
  • 82
gangsta
  • 837
  • 2
  • 7
  • 10
  • 1
    Sounds like a bug. Can you please create a [bug report](http://jira.codehaus.org/browse/SUREFIRE) if there isn't one already. – Stephen Connolly Feb 02 '13 at 10:54
  • 1
    Thanks for your input. I'll try to create a new, simpler project that demonstrates the same issue. Then open a bug report. – gangsta Feb 04 '13 at 14:31
  • 5
    Have you checked newer version cause in the meantime we are at 2.18.1 ? – khmarbaise Mar 03 '15 at 16:55
  • 1
    Please post the versions of Java, Maven and Spring you are using and your configuration of the `maven-surefire-plugin`. – hzpz Jul 28 '15 at 18:42
  • Sounds to me like it's RunWith that can't be found. Is it possible you have two versions of Surefire running in the same classloader? Is one of your dependencies loading a different version? This looks a lot like the sort of problem you might encounter when attempting to load two different versions of the same class. – Zenexer Jun 27 '16 at 09:32
  • I had the same exception when the annotation parameter (SpringJunit4ClassRunner.class in this case) was not on my classpath. – louisgab Feb 22 '17 at 18:32

1 Answers1

2

Run mvn dependency:resolve

Exclude any 3.x version of JUnit that may have crept in.

Make sure there are no TestNG dependencies, if there are it will load TestNG annotations and not the JUnit ones you need.

UserF40
  • 3,533
  • 2
  • 23
  • 34