Skip to content

Suppressing compilation warnings

Daniel Molinero edited this page Feb 1, 2019 · 7 revisions

Toothpick generates compilation warnings in 2 cases:

  • A class has injected fields but has no injected constructor, and the default constructor is private.
  • A class has injected fields but has no injected constructor, and no public default constructor.

For both cases Toothpick will not be able to generate factories for the class. Thus, the warning is displayed.

Sometimes, when the class is a DI graph root, that is the desired behavior. To remove the compile warning for those cases, the @SuppressWarning annotation can be used with the value Injectable:

@SuppressWarnings("injectable")
class MyView {
  ...
  public MyView() {
    ...
    Toothpick.inject(this, scope);
  }
  ...
}

It is possible to make TP fail builds instead of issuing warnings: use -Atoothpick_crash_when_no_factory_can_be_created=true.


@Inject annotated methods should have protect visibility: class#method

This warning is emitted when an @Inject annotated method has a visibility modifier different from package-private (no explicit visibility modifier). See issue #119, as you will see, doing so allows to override injected methods and this can quickly lead to highly complex situation. TP will warn you.It is possible to suppress this warning by annotated the method with @SuppressWarning("visible").

It is possible to make TP fail builds instead of issuing warnings: use -Atoothpick_crash_when_injected_method_is_not_package=true.