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

Cannot mock Exceptions/ Throwable with @Mocked annotation #457

Sebsen opened this issue Sep 14, 2017 · 2 comments

Cannot mock Exceptions/ Throwable with @Mocked annotation #457

Sebsen opened this issue Sep 14, 2017 · 2 comments


Copy link

@Sebsen Sebsen commented Sep 14, 2017

Please provide the following information:

  • Version of JMockit that was used: Update from Version 1.30 to Version 1.34

  • Description of the problem:
    Since the update from JMockit version 1.30 to version 1.34 we're not able to mock any type of exception (standard JDK type neither custom created types) with JMockit's @mock annotation - bug or feature?

From eclipse JUnit tests stop to run cause an StackOverflowError claiming a NoClassDefFoundError/ ClassNotFoundException when an exception type field is annotated with @mocked annotation. From ANT execution crashes with an "JVM exited abnormally" error. @tested on the other hand works fine though.

When an exception type is mocked with @mocked annotation as method parameter the test just fails directly with the appropriate failure message: "java.lang.IllegalArgumentException: Class java.lang.Throwable is not mockable". Even though it's a standard JDK exception type or a custom one.

In JMockit version 1.32 the mocking of exception types worked fine, so I think the behaviour changed with the release of version 1.33 (which became extended features with the @tested annotation).


@Sebsen Sebsen changed the title Cannot mock Exceptions/ Throwable with @Mock annotation Cannot mock Exceptions/ Throwable with @Mocked annotation Sep 14, 2017
@rliesenfeld rliesenfeld self-assigned this Sep 15, 2017
Copy link

@rliesenfeld rliesenfeld commented Sep 15, 2017

Indeed, the outcome from @Mocked SomeException should be the same as @Injectable SomeException.

Thanks for reporting the bug!

Copy link

@charlesritchea charlesritchea commented Oct 6, 2017

I still can't mock any Exception in 1.35 (but could in 1.33) I'm unclear on the status of this issue.

@jmockit jmockit locked and limited conversation to collaborators Oct 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

No branches or pull requests

3 participants