Suppress "variable is never assigned" warning in IntelliJ IDEA

You could use an annotation to mark it as an injected field. (similar to how it would treat @EJB). The IntelliJ inspections (at least with version 10.5) allow you to configure your own annotations to mark fields as being injected.

Select Analyze, Inspect Code from the menu and then go to the unused declaration inspection and you can configure an annotation.


  1. run analysis: Analyze > Inpect Code...
  2. Right click on Unused Declaration (below the Declaration redundancy tree node)
  3. Click on the "Configure Annotations..."
  4. Add com.google.google.inject.Inject and javax.inject.Inject

To configure annotations in Android Studio 1.1.0 after inspecting your code right click Unused declaration -> Edit Settings -> Configure annotations.

Android Studio 1.1.0

Android Studio 1.1.0


Settings -> Editor -> Inspections -> Declaration Redundancy -> Unused declaration -> Entry points -> Annotations

A new popup opens, split into 2 different areas: "Mark as entry point if annotated by" and "Mark field as implicitly written if annotated by". Only in the latter you click the "+" icon (Add Annotation Class) and select Autowired annotation (or whatever annotation you're using for dependency injection).

This will disable the warning "private field is never assigned" but will not disable the warning "private field is never used" in case you never use the field in the class code, which is the desirable behaviour.

enter image description here

This worked on IntelliJ IDEA Community Edition 2018.3.3 and 2020.2


If you popup the actions hint window (alt + Enter on Mac), it should suggest you to suppress warning for Inject annotation