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

GIN does not respect injection order when subclassing #199

Open
GoogleCodeExporter opened this issue Mar 13, 2015 · 1 comment
Open

GIN does not respect injection order when subclassing #199

GoogleCodeExporter opened this issue Mar 13, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
According to the Guice injection points document at:
https://github.com/google/guice/wiki/InjectionPoints

injection methods of super classes are called before the methods of a subclass.

Here is some small unit test for Guice that shows that the correct order is 
first ThingA.inject() and then ThingB.anotherInject().

If you use GIN, ThingB.anotherInject() is invoked before ThingA.inject()

public class InjectInheritance {

  static class ThingA {
    boolean initialized;

    @Inject
    public void inject() {
      this.initialized = true;
      System.out.println("ThingA:inject called");
    }
  }

  static class ThingB extends ThingA {
    private boolean testOK = false;

    @Inject
    public void anotherInject() {
      testOK = this.initialized;
      System.out.println("ThingB:anotherInject called");
    }

    public boolean isSuccess() {
      return testOK;
    }
  }

  @Test
  public void guiceMethodInjectionInheritance() {
    Module module = new AbstractModule() {
      @Override
      protected void configure() {
      }
    };
    Injector guice = Guice.createInjector(module);
    ThingB b = guice.getInstance(ThingB.class);
    assertTrue(b.isSuccess());
  }

  // This part of the code needs to be executed by GIN.
  public void ginInheritance() {
    App app = GWT.create( App.class);
    ThingB b = app.createB();
    assertTrue(b.isSuccess());
  }

  @GinModules(MyGinModule.class)
  static interface App extends Ginjector {
    public ThingB createB();
  }

  static class MyGinModule extends AbstractGinModule {
    @Override
    protected void configure() {
    }
  }

What is the expected output? What do you see instead?
I expect this order of invocation
ThingA.inject();
ThingB.anotherInject();

However I get this in Gin:
ThingB.anotherInject();
ThingA.inject();


What version of the product are you using? On what operating system?
GWT 2.6.1 / GIN 2.1.2

Please provide any additional information below.


Original issue reported on code.google.com by david.nouls on 24 Sep 2014 at 2:21

@GoogleCodeExporter
Copy link
Author

I tried with GIN 2.1.2 and GWT 2.7.0 and the problem still exists.
I wrote a simple unittest that exposes the problem.
It looks like the name of the method influences the orde in which the methods 
are injected.
So if my base class has something like injectZ and the derived class has 
injectA then injectA is done before injectZ. Which can cause issues if you 
method injection depends on the base class to be fully injected.
I attached my example unittest to show the problem.

Original comment by david.nouls on 30 Jan 2015 at 9:37

Attachments:

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

No branches or pull requests

1 participant