IntelliJ IDEA
 
Get IntelliJ IDEA

Analyze data flow

Last modified: 10 October 2024

When working with large codebases, it is sometimes difficult to figure out how data is processed and how the workflows could be improved to make the code more performant and readable. To facilitate this, IntelliJ IDEA dataflow analysis enables you to trace all the possible data transformations without running the program. The information can be used to improve the design of the app and diagnose bugs before they manifest themselves.

Data flow analysis provides the information on:

  • What happens to the data downstream of a method or expression: what are the consumers and what possible values can be produced.

  • All the possible input values a method can have and where particular values are coming from.

  • Whether a variable can possibly be null. Using this information, you can prevent unexpected NullPointerExceptions and optimize your workflows by removing redundant null checks and @Nullable annotations.

A tool window opens containing the results of the analysis. They are organized in nodes, each representing a data flow step.

Analysis result in a tool window

In the example:

  • The getComplete() method returns the value of the complete variable.

  • The complete variable can be assigned null during initialization or get any value in the setComplete method.

  • The setComplete() method is called at lines 17 and 48 and assign the values false and true respectively.