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

Overridden methods from base class call methods from fake subclass #705

Open
jmf-tls opened this issue Mar 8, 2021 · 1 comment
Open

Comments

@jmf-tls
Copy link

jmf-tls commented Mar 8, 2021

  • Version of JMockit that was used:
    1.49 (also in master branch at 5c6a2df)

  • Description of the problem or enhancement request:

Consider this test scenario

   public static class BaseClass {
      protected int doSomething() { return 1; }
   }

   public static class Subclass extends BaseClass {
      @Override protected int doSomething() { return super.doSomething() + 1; }
   }

   public static final class FakeForSubclass extends MockUp<Subclass> {
      @Mock public int doSomething(Invocation inv) { return inv.proceed(); }
   }

When a test uses FakeForSubclass and creates an instance of Subclass, calling subclass.doSomething() results in a StackOverflowError.
Initially the invocation proceeds to run the code on Subclass, which calls the method on the base class that it overrides.
This call is intercepted by FakeForSubclass, which calls the code in Subclass again, resulting in a loop that ends in the StackOverflowError. The code in BaseClassshould be called instead.

I created a pull request that adds a validation for this issue on the FakedClassWithSuperClassTest: #704

@jmf-tls
Copy link
Author

jmf-tls commented Mar 8, 2021

Probably related with #671

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

No branches or pull requests

1 participant