Inspectopedia 2024.3 Help

Class is exposed outside of its visibility scope

Reports usages of classes in a field or method signature where the class has less visibility than the member that uses it. While legal Java, such members cannot be used outside of the visibility scope of the class type they reference.

Example:

public class Parent { public Child getChild() { return new Child(); } private class Child {} }

Additionally, in Java 9 and higher, a module may hide some of its classes from other modules by not exporting their packages. However, if a member that is part of the exported API references a non-exported class in its signature, such a member cannot be used outside of the module.

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.

ClassEscapesDefinedScope
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

Configure the inspection:

  • Use the Report non-exported classes exposed in module API (Java 9+) option to report module API members that expose non-exported classes.

    Note that the language level of the project or module needs to be 9 or higher for this option.

  • Use the Report non-accessible classes exposed in public API option to report on public members that expose classes with a smaller visibility scope.

  • Use the Report private classes exposed in package-local API option to report on package-local members that expose private classes.

Inspection options

Here you can find the description of settings available for the Class is exposed outside of its visibility scope inspection, and the reference of their default values.

Report non-exported classes exposed in module API (Java 9+)

Default: Selected

Report non-accessible classes exposed in public API

Default: Selected

Report private classes exposed in package-local API

Not selected

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