Clamp function can be used
Reports combinations of Math.max() and Math.min() that are equivalent to Math.clamp().
Example:
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.
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:
braveModeDefault 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:
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: |