Inspectopedia 2025.3 Help

Redundant local variable

Reports unnecessary local variables that add nothing to the comprehensibility of a method, including:

  • Local variables that are immediately returned.

  • Local variables that are immediately assigned to another variable and then not used.

  • Local variables that always have the same value as another local variable or parameter.

Example:

boolean yes() { boolean b = true; return b; }

After the quick-fix is applied:

boolean yes() { return true; }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

UnnecessaryLocalVariable
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Data flow

Configure the inspection:

  • Use the Ignore immediately returned or thrown variables option to ignore immediately returned or thrown variables. Some coding styles suggest using such variables for clarity and ease of debugging.

  • Use the Ignore variables which have an annotation option to ignore annotated variables.

Inspection ID: UnnecessaryLocalVariable

Inspection options

Here you can find the description of settings available for the Redundant local variable inspection, and the reference of their default values.

Ignore immediately returned or thrown variables

Option ID:

m_ignoreImmediatelyReturnedVariables

Default value:

Not selected
Ignore variables which have an annotation

Option ID:

m_ignoreAnnotatedVariablesNew

Default value:

Selected

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection UnnecessaryLocalVariable

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.3, Qodana for JVM 2025.3,

Last modified: 03 December 2025