Inspectopedia 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); } }; } }

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023