Inspectopedia 2024.3 Help

'return' separated from the result computation

Reports return statements that return a local variable where the value of the variable is computed somewhere else within the same method.

The quick-fix inlines the returned variable by moving the return statement to the location in which the value of the variable is computed. When the returned value can't be inlined into the return statement, the quick-fix attempts to move the return statement as close to the computation of the returned value as possible.

Example:

int n = -1; for (int i = 0; i < a.length; i++) { if (a[i] == b) { n = i; break; } } return n;

After the quick-fix is applied:

int n = -1; for (int i = 0; i < a.length; i++) { if (a[i] == b) { return i; } } return n;

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.

ReturnSeparatedFromComputation
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 | Code style issues

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