New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage tool: Null Pointer Exception with inner enum. #331

Closed
AlexStasko opened this Issue Sep 7, 2016 · 0 comments

Comments

2 participants
@AlexStasko

AlexStasko commented Sep 7, 2016

I use JMockit 1.27 for code coverage
Java 1.8.92
TestNG 6.9.12
Guava 19.0.

private static final String URL_TO_LOGO_IMAGE = "http://test.example.com/logo.jpg";

@Test
public void testInitialization() {
    List<Pair<Image.DimensionType, String>> dimensions = Lists.newArrayList();
    Pair<Image.DimensionType, String> pairL = new ImmutablePair<>(DimensionType.LARGE,
            URL_TO_LOGO_IMAGE);
    dimensions.add(pairL);
    Image image = new Image.ImageBuilder().withDimensions(dimensions).build();
    assertSame(URL_TO_LOGO_IMAGE, image.getDimensionsMap().get(DimensionType.LARGE));
}

In console prints following error

Gradle suite > Gradle test > com.example.ImageTest.testInitialization FAILED
java.lang.NullPointerException
at java.util.EnumMap.(EnumMap.java:139)
at com.example.Image$ImageBuilder.withDimensions(Image.java:76)
at com.example.ImageTest.testInitialization(ImageTest.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.runTests(TestNGTestClassProcessor.java:133)
at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:83)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:377)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
JMockit: Coverage report written to D:\work\Idea\myproject\build\reports\coverage

Issue is reproduced with this example project myproject.zip

Test successfully runs if extract enum as normal (not inner) java class.
Also test success when code coverage tool is off.

Thank you,
Alex

@rliesenfeld rliesenfeld added the bug label Sep 7, 2016

@rliesenfeld rliesenfeld self-assigned this Sep 7, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment