rspec/rules/S2384/description.adoc

8 lines
584 B
Plaintext
Raw Normal View History

2020-06-30 12:48:07 +02:00
Mutable objects are those whose state can be changed. For instance, an array is mutable, but a String is not. Mutable class members should never be returned to a caller or accepted and stored directly. Doing so leaves you vulnerable to unexpected changes in your class state.
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
Instead use an unmodifiable ``++Collection++`` (via ``++Collections.unmodifiableCollection++``, ``++Collections.unmodifiableList++``, ...) or make a copy of the mutable object, and store or return the copy instead.
2020-06-30 12:48:07 +02:00
2021-02-02 15:02:10 +01:00
2020-06-30 12:48:07 +02:00
This rule checks that arrays, collections and Dates are not stored or returned directly.