Inspectopedia 2025.3 Help

Assignment or return of field with mutable type

Reports return of, or assignment from a method parameter to a field of an array or a mutable type such as Collection, Date, Map, Calendar, etc.

Because such types are mutable, this construct may result in unexpected modifications of an object's state from outside the owning class. Although this construct may be useful for performance reasons, it is inherently prone to bugs.

The following mutable types are reported:

  • java.util.Date

  • java.util.Calendar

  • java.util.Collection

  • java.util.Map

  • com.google.common.collect.Multimap

  • com.google.common.collect.Table

The quick-fix adds a call to the field's .clone() method for arrays or uses an unmodifiable collection wrapper.

Example:

import java.util.*; class Log { private String[] messages = {"one", "two", "three"}; private Map<String, String> map = new HashMap<>(); String[] getMessages() { return messages; // warning: Return of String[] field 'messages' } Map<String, String> mapping() { return map; // warning: Return of Map<String, String> field 'map' } }

After the quick-fix is applied:

import java.util.*; class Log { String[] messages = {"one", "two", "three"}; private Map<String, String> map = new HashMap<>(); String[] getMessages() { return messages.clone(); } Map<String, String> mapping() { return Collections.unmodifiableMap(map); } }

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.

AssignmentOrReturnOfFieldWithMutableType
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 | Encapsulation

Use the Ignore assignments in and returns from private methods option to ignore assignments and returns in private methods.

Inspection ID: AssignmentOrReturnOfFieldWithMutableType

Inspection options

Here you can find the description of settings available for the Assignment or return of field with mutable type inspection, and the reference of their default values.

Ignore assignments in and returns from private methods

Option ID:

ignorePrivateMethods

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 AssignmentOrReturnOfFieldWithMutableType

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.3, Qodana for JVM 2025.3,

Last modified: 03 December 2025