Skip to content
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

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

Closed
PrzemekCh opened this issue Apr 10, 2015 · 4 comments
Closed
Assignees
Labels
bug

Comments

@PrzemekCh
Copy link

@PrzemekCh PrzemekCh commented Apr 10, 2015

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.

Copy link
Member

@rliesenfeld 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.

Copy link
Author

@PrzemekCh PrzemekCh commented Apr 13, 2015

I've send You the jar over email.

@PrzemekCh

This comment has been minimized.

Copy link
Author

@PrzemekCh PrzemekCh commented Apr 13, 2015

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.

Copy link
Member

@rliesenfeld 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
2 participants
You can’t perform that action at this time.