Inspectopedia
 
2024.3

Class is exposed outside of its visibility scope

Warning
New
Last modified: 03 December 2024

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:

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.

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.