Inspectopedia Help

Unused declaration

Reports classes, methods, or fields that are not used or unreachable from the entry points.

An entry point can be a main method, tests, classes from outside the specified scope, classes accessible from module-info.java, and so on. It is possible to configure custom entry points by using name patterns or annotations.

Example:

public class Department { private Organization myOrganization; }

In this example, Department explicitly references Organization but if Department class itself is unused, then inspection will report both classes.

The inspection also reports parameters that are not used by their methods and all method implementations and overriders, as well as local variables that are declared but not used.

Note: Some unused members may not be reported during in-editor code highlighting. For performance reasons, a non-private member is checked only when its name rarely occurs in the project. To see all results, run the inspection by selecting Code | Inspect Code or Code | Analyze Code | Run Inspection by Name from the main menu.

Use the visibility settings below to configure members to be reported. For example, configuring report private methods only means that public methods of private inner class will be reported but protected methods of top level class will be ignored.

Use the entry points tab to configure entry points to be considered during the inspection run.

You can add entry points manually when inspection results are ready.

If your code uses unsupported frameworks, there are several options:

  • If the framework relies on annotations, use the Annotations... button to configure the framework's annotations.

  • If the framework doesn't rely on annotations, try to configure class name patterns that are expected by the framework.

This way the annotated code accessible by the framework internals will be treated as used.

Inspection options

Option

Type

Default

TabSet

None

Members to report

Tab

None

Classes

Checkbox

true

Dropdown

public

Inner classes

Checkbox

true

Dropdown

public

Fields

Checkbox

true

Dropdown

public

Methods

Checkbox

true

Dropdown

public

Getters/setters

Checkbox

false

Parameters in

Checkbox

true

Dropdown

public

Excluding hierarchy

Checkbox

false

Local variables

Checkbox

true

Entry points

Tab

None

When entry points are in test sources, mark callees as

Dropdown

used

Entry points

Group

None

HorizontalStack

None

Custom

None

Custom

None

void main(String args[]) methods

Checkbox

true

Applets

Checkbox

true

Servlets

Checkbox

true

Classes exposed with module-info

Checkbox

true

Android components

Checkbox

true

Compose Preview

Checkbox

true

Deprecated members

Checkbox

true

JavaFX Applications

Checkbox

true

JUnit static methods

Checkbox

true

JUnit test cases

Checkbox

true

TestNG test cases

Checkbox

true

Classes with usages in non-Java files

Checkbox

true

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023