1

I am using cobertura-maven-plugin-2.7 and I am getting an error when I do a maven build.

But when I run the Junit test case independently it is successfully executed.

Environment:

Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T12:37:52-05:00) Java version: 1.8.0_51, 
vendor: Oracle Corporation Java home: F:\Java\JDK8_51\jre Default locale: en_US, 
platform encoding: Cp1252 OS name: "windows 7", 
version: "6.1", 
arch: "amd64", 
family: "dos" Junit 4.12

ERROR TRACE:

java.lang.ExceptionInInitializerError
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: java.lang.NullPointerException
    at CustomClass.<clinit>(CustomClass.java:33)

at line 33:(shown below)-LoggerFactory(of type org.slf4j.LoggerFactory) is null

private static final Logger LOGGER = LoggerFactory
        .getLogger(CustomClass.class);

UPDATE:

Hi.Thanks I did make some changes to code to remove the "static" references which are not needed.But I still have issues in mocking any of the interfaces which work fine if I run individually using Junit but fail when I do a build using cobertura.Any inputs please? Sorry for not posting another question as the issue of not able to build using cobertura 2.7 still persists but in another form.

1 Answers1

1

You might have run into a bug: Instrumented classes throw NPE during static initialization.

hzpz
  • 7,536
  • 1
  • 38
  • 44
  • Hi.Thanks I did make some changes to code to resolve the "static" references.But I still have issues in mocking some interfaces which work fine if I run individually using Junit but fail when I do a build using cobertura.Any inputs please? – kartheek desineedi Aug 20 '15 at 17:24
  • If you found a solution to your problem, please [answer your question](http://stackoverflow.com/help/self-answer) so that others may benefit from it. If you have another problem, please [ask another question](http://stackoverflow.com/questions/ask). Comments are not the right place for this. – hzpz Aug 20 '15 at 19:41