Inspectopedia 2025.2 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 value:

Selected
Report non-accessible classes exposed in public API

Default value:

Selected
Report private classes exposed in package-local API

Default value:

Not 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 ClassEscapesDefinedScope

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.2, Qodana for JVM 2025.2,

Last modified: 18 September 2025