java.lang.NullPointerException exception since with jmockit 1.10 onwards #162

Closed
PrzemekCh opened this Issue Apr 10, 2015 · 4 comments

Comments

2 participants
@PrzemekCh

While trying to generate a mockup for
oracle.wsm.policy.model.impl.SimpleAssertion

SimpleAssertion simpleAsserter = new MockUp() {

}.getMockInstance();

if fails with jmockup since version 1.10+.
In previous versions it works.

java.lang.NullPointerException
at java.util.HashMap.(HashMap.java:223)
at oracle.wsm.policy.model.impl.SimpleAssertion.hashCode(SimpleAssertion.java:777)
at java.util.HashMap.getEntry(HashMap.java:344)
at java.util.HashMap.containsKey(HashMap.java:335)
at java.util.HashSet.contains(HashSet.java:184)
at java.util.AbstractCollection.retainAll(AbstractCollection.java:369)
at mockit.internal.state.MockClasses$SavePoint.rollback(MockClasses.java:165)
at mockit.internal.state.SavePoint.rollback(SavePoint.java:42)
at mockit.integration.internal.TestRunnerDecorator.discardTestLevelMockedTypes(TestRunnerDecorator.java:123)
at mockit.integration.internal.TestRunnerDecorator.cleanUpMocks(TestRunnerDecorator.java:85)
at mockit.integration.internal.TestRunnerDecorator.cleanUpMocksFromPreviousTestClass(TestRunnerDecorator.java:80)
at mockit.integration.junit4.internal.RunNotifierDecorator.fireTestRunFinished(RunNotifierDecorator.java:28)
at org.junit.runner.notification.RunNotifier.fireTestRunFinished(RunNotifier.java)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:51)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld Apr 10, 2015

Member

Is this class "oracle.wsm.policy.model.impl.SimpleAssertion" available from some artifact in the Maven Central repository? If not (and apparently it isn't), I won't be able to examine the problem.

Member

rliesenfeld commented Apr 10, 2015

Is this class "oracle.wsm.policy.model.impl.SimpleAssertion" available from some artifact in the Maven Central repository? If not (and apparently it isn't), I won't be able to examine the problem.

@PrzemekCh

This comment has been minimized.

Show comment
Hide comment
@PrzemekCh

PrzemekCh Apr 13, 2015

I've send You the jar over email.

I've send You the jar over email.

@PrzemekCh

This comment has been minimized.

Show comment
Hide comment
@PrzemekCh

PrzemekCh Apr 13, 2015

And in previous versions it will not throw an error but the instance created is always null.

And in previous versions it will not throw an error but the instance created is always null.

@rliesenfeld rliesenfeld added bug and removed could not reproduce labels Apr 13, 2015

@rliesenfeld rliesenfeld self-assigned this Apr 13, 2015

@rliesenfeld rliesenfeld reopened this Apr 13, 2015

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld Apr 13, 2015

Member

Thanks, reproduced it now. As a workaround, consider not calling "getMockInstance()". When mocking-up a class, this method is not meant to be used in the vast majority of cases, as it creates an uninitialized instance for a partially mocked class; so, if you use it there is a good chance of later getting a NPE or some other exception due to executing unmocked methods on an uninitialized instance.

Member

rliesenfeld commented Apr 13, 2015

Thanks, reproduced it now. As a workaround, consider not calling "getMockInstance()". When mocking-up a class, this method is not meant to be used in the vast majority of cases, as it creates an uninitialized instance for a partially mocked class; so, if you use it there is a good chance of later getting a NPE or some other exception due to executing unmocked methods on an uninitialized instance.

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