Inspectopedia 2024.3 Help

Method with multiple return points

Reports methods whose number of return points exceeds the specified maximum. Methods with too many return points may be confusing and hard to refactor.

A return point is either a return statement or a falling through the bottom of a void method or constructor.

Example:

The method below is reported if only two return statements are allowed:

void doSmth(User[] users) { for (User user : users) { if (cond1(user)) { user.setId(getId()); return; } else if (cond2(user)) { if (cond3(user)) { user.setId(getId()); return; } } } }

Consider rewriting the method so it becomes easier to understand:

void doSmth(User[] users) { for (User user : users) { if (cond1(user) || cond2(user) && cond3(user)) { user.setId(getId()); return; } } }

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.

MethodWithMultipleReturnPoints
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 | Method metrics

Configure the inspection:

  • Use the Return point limit field to specify the maximum allowed number of return points for a method.

  • Use the Ignore guard clauses option to ignore guard clauses. A guard clause is an if statement that contains only a return statement

  • Use the Ignore for 'equals()' methods option to ignore return points inside equals() methods.

Inspection options

Here you can find the description of settings available for the Method with multiple return points inspection, and the reference of their default values.

Return point limit

1

Ignore guard clauses

Not selected

Ignore for 'equals()' methods

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