Inspectopedia 2025.2 Help

Simplifiable 'Map' operations

Reports common usage patterns of java.util.Map and suggests replacing them with: getOrDefault(), computeIfAbsent(), putIfAbsent(), merge(), or replaceAll().

Example:

map.containsKey(key) ? map.get(key) : "default";

After the quick-fix is applied:

map.getOrDefault(key, "default");

Example:

List<String> list = map.get(key); if (list == null) { list = new ArrayList<>(); map.put(key, list); }

After the quick-fix is applied:

map.computeIfAbsent(key, localKey -> new ArrayList<>());

Example:

Integer val = map.get(key); if (val == null) map.put(key, 1); else map.put(key, val + 1);

After the quick-fix is applied:

map.merge(key, 1, (localKey, localValue) -> localValue + 1);

Example:

for (Map.Entry<String, String> entry : map.entrySet()) { map.put(entry.getKey(), transform(entry.getValue())); }

After the quick-fix is applied:

map.replaceAll((localKey, localValue) -> transform(localValue));

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.

Java8MapApi
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 8

Note that the replacement with computeIfAbsent() or merge() might work incorrectly for some Map implementations if the code extracted to the lambda expression modifies the same Map. By default, the warning doesn't appear if this code might have side effects. If necessary, enable the Suggest replacement even if lambda may have side effects option to always show the warning.

Also, due to different handling of the null value in old methods like put() and newer methods like computeIfAbsent() or merge(), semantics might change if storing the null value into given Map is important. The inspection won't suggest the replacement when the value is statically known to be nullable, but for values with unknown nullability the replacement is still suggested. In these cases, we recommended suppressing the warning and adding an explanatory comment.

This inspection depends on the Java feature 'Lambda methods in collections', which is available since Java 8.

Inspection options

Here you can find the description of settings available for the Simplifiable 'Map' operations inspection, and the reference of their default values.

Suggest conversion to Map.computeIfAbsent

Default value:

Selected
Suggest conversion to Map.getOrDefault

Default value:

Selected
Suggest conversion to Map.putIfAbsent

Default value:

Selected
Suggest conversion to Map.merge

Default value:

Selected
Suggest conversion to Map.replaceAll

Default value:

Selected
Treat 'get(k) != null' the same as 'containsKey(k)' (may change semantics)

Default value:

Not selected
Suggest replacement even if lambda may have side effects

Default value:

Not 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 Java8MapApi

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

Last modified: 18 September 2025