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

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

Projects

None yet

2 participants

@AlexStasko
AlexStasko commented Sep 7, 2016 edited

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
@rliesenfeld rliesenfeld added a commit that closed this issue Sep 7, 2016
@rliesenfeld rliesenfeld Fixed bug in path coverage with call points, where a NPE would happen…
… from a nested enum accessed from a nested class, due to uninitialized path state; closes #331.
fdc3969
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment