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

Mocked class with method that returns a Throwable subclass throws "not mockable" error #437

ogray58 opened this issue Jul 27, 2017 · 2 comments


Copy link

@ogray58 ogray58 commented Jul 27, 2017

JMockit: 1.33 (Note: I also tried building from the current head of the JMockit master branch and it also failed there)
JUnit: 4.11
Java: 1.8.0_66

I'm guessing that it tries to return a cascaded mock, and since Throwable can't be mocked it throws an error. Note that this doesn't occur if TestClass.getMyThrowable() returns a Throwable instead of a MyThrowable.

Code to Reproduce

@Mocked private TestClass mockedTestClass = null;

public void test()

public static class TestClass
	public MyThrowable getMyThrowable()
		return new MyThrowable();

public static class MyThrowable extends Throwable {}
Copy link

@Milbor-zz Milbor-zz commented Jul 31, 2017


    private IOException exception;

java.lang.IllegalArgumentException: Class java.lang.Throwable is not mockable

same bug or should I open new issue?

Copy link

@rliesenfeld rliesenfeld commented Aug 7, 2017

@Milbor It's a feature, unless someone can show a legitimate need to mock an exception class, especially a standard one.

@jmockit jmockit deleted a comment from Milbor-zz Aug 8, 2017
@jmockit jmockit locked and limited conversation to collaborators Aug 8, 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