Inspectopedia 2024.3 Help

Access to inherited field looks like access to element from surrounding code

Reports access to a superclass field from an anonymous, inner or local class, if a local variable, parameter, or field with the same name is available in the code surrounding the class. In this case it may seem that an element from the surrounding code is accessed, when in fact it is an access to a field from the superclass.

To clarify the intent of the code, it is recommended to add an explicit super qualifier to the field access.

Example:

class First { protected String ambiguous; } class Second { void foo(String ambiguous) { new First() { { System.out.println(ambiguous); // the field is accessed, not the parameter } }; } }

After the quick-fix is applied:

class First { protected String ambiguous; } class Second { void foo(String ambiguous) { new First() { { System.out.println(super.ambiguous); } }; } }

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.

AmbiguousFieldAccess
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

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.3, Qodana for JVM 2024.3,

Can be installed with plugin:

Java, 243.23126

Last modified: 03 December 2024