Inspectopedia Help

Local variable hides field

Reports local variables named identically to a field of a surrounding class. As a result of such naming, you may accidentally use the variable where the identically named field is intended.

A quick-fix is suggested to rename the variable.


public class Foo { public Object foo; void bar() { Object o = new Object() { void baz() { Object foo; // Local variable 'foo' hides field in class 'Foo' } }; } }

Locating this inspection


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

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 | Visibility

You can configure the following options for this inspection:

  1. Ignore non-accessible fields - ignore local variables named identically to superclass fields that are not visible (for example, because they are private).

  2. Ignore local variables in a static context hiding non-static fields - for example when the local variable is inside a static method or inside a method which is inside a static inner class.

Inspection options

Here you can find the description of settings available for the Local variable hides field inspection, and the reference of their default values.

Ignore non-accessible fields

Default: Selected

Ignore local variables in a static context hiding non-static fields

Default: Selected


By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Java, 241.18072

Last modified: 18 June 2024