Recipe Name:
Guice Injected Field Not Public
Description:
If the Injected field is not public then the code might not be wired up.
Level:
warning
Language:
  • java
Tags:
  • Guice
  • dependency injection
  • framework specific
  • quality
Documentation

Guice can only perform injection into fields if the class is publicly accessible.

Before
private class MyClass {
  @Inject
  private OtherClass dependency;

  public MyClass() {}
}
After
public class MyClass {
  @Inject
  private OtherClass dependency;

  public MyClass() {}
}
Recipe
id: scw:guice:public-injected-fields
version: 10
metadata:
  name: Guice Injected Field Not Public
  shortDescription: If the Injected field is not public then the code might not be wired up.
  level: warning
  language: java
  enabled: true
  comment: ""
  descriptionFile: descriptions/Guice_Injected_Field_Not_Public.html
  tags: Guice;dependency injection;framework specific;quality
search:
  field:
    annotation:
      type: com.google.inject.Inject
    in:
      typeDeclaration:
        without:
          modifier: public
availableFixes:
- name: Change class to public. Remember to also request injection on this class.
  actions:
  - changeModifiers:
      visibility: public
      target: parentClass