Skip to content

GIN does not respect injection order when subclassing #199

@GoogleCodeExporter

Description

@GoogleCodeExporter
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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions