Skip to content

Non-static providers inside abstract modules cause runtime crashes #621

@AttwellBrian

Description

@AttwellBrian

If you forget to add static to an abstract module your app will crash at runtime. This should be prevented at compile time.

Example:
Suppose you have a nice abstract module such as the following example:

class SomeOuterClass {
  @dagger.Module
  public abstract static class Module {
      @NonNull
      @OnlineScope
      @Provides
      static A a() {
          return new A();
      }
  }

  @OnlineScope
  @dagger.Component(modules = Module.class, dependencies = ParentComponent.class)
  interface Component {
      @dagger.Component.Builder
      interface Builder {
          @BindsInstance
          Builder interactor(OnlineInteractor interactor);

          @BindsInstance
          Builder view(Observable<Optional<OnlineView>> view);

          Builder parentComponent(ParentComponent component);
          Component build();
      }
  }
}

Next, lets add a new provider to the Module.

@dagger.Module
public abstract static class Module {
    @NonNull
    @OnlineScope
    @Provides
    static A a() {
        return new A();
       }
   }

    @NonNull
    @OnlineScope
    @Provides
    B b() {
        return new B();
    }
}

Oops! We forgot to add static to the second provider. This example now crashes at runtime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions