Inspectopedia 2026.1 Help

Clamp function can be used

Reports combinations of Math.max() and Math.min() that are equivalent to Math.clamp().

Example:

int min = 5, max = 10; /*before*/ input = Math.max(Math.min(max, input), min); /*after*/ input = Math.clamp(input, min, max);

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.

MathClampMigration
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 | Java language level migration aids | Java 21

By default, the inspection only shows when it can statically prove that min is lesser or equal than max. This is done to avoid any IllegalArgumentException due to semantics changes. If you want the inspection to show up nonetheless, you can enable the Warn even if the lower bound could be higher than the upper bound option.

This inspection depends on the Java feature 'Clamp methods in standard library', which is available since Java 21.

Inspection ID: MathClampMigration

New in 2026.1

Inspection options

Here you can find the description of settings available for the Clamp function can be used inspection, and the reference of their default values.

Warn even if the lower bound could be higher than the upper bound

Option ID:

braveMode

Default value:

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 MathClampMigration

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 2026.1, Qodana for JVM 2026.1,

Last modified: 31 March 2026